Unable to use Arrow functions inside React component class [duplicate]

It’s not the arrow function that’s causing a problem here. Class properties are not part of the ES6 specification.

handleUpdateInput = (value) => {
  // ...
};

If you want to be able to transform this code, you’ll need to add the class properties babel plugin.

Alternatively, this transform is provided as part of Babel’s stage 2 preset.

Using an arrow function with a class property ensures that the method is always invoked with the component as the value for this, meaning that the manual rebinding here is redundant.

this.handleUpdateInput = this.handleUpdateInput.bind (this);

Leave a Comment