1

I have the next code:

 close = () => {
     this.setState({ open: false });
     this.props.onUpdate(this.props.defaultValue);
 }

But I am getting the next error message:

ERROR in ./ui/usersModule/scripts/usersTable.jsx
Module build failed: SyntaxError: 


 Error: Unexpected token (232:8)

  230 |   }
  231 |
> 232 |   close = () => {
      |         ^
  233 |     this.setState({ open: false });
  234 |     this.props.onUpdate(this.props.defaultValue);
  235 |   }

I saw that it compiles on the original code but for some reason it does not compile in my machine. I need to call it from:

onClick={ this.close }

Why could be my error? is there another way to call that close function?

Jose Cabrera Zuniga
  • 2,348
  • 3
  • 31
  • 56

1 Answers1

1

If you're using the typical webpack+babel setup to compile ES6+ code, you need babel-plugin-transform-class-properties.

Install the module, and add this under babel to your package.json, or your .babelrc:

  "plugins": [
    "transform-class-properties"
  ]
salezica
  • 74,081
  • 25
  • 105
  • 166