score:21

Accepted answer

You need an equals sign when using class property initializers.

export default class EventTags extends React.Component {
  showAll = () => {
    this.setState({
      showAll: true,
      showBtn: false
    });
  };
}
  • Ensure you have the transform-class-properties Babel transform enabled
  • Unlike class methods, class property initializers should be followed by semicolons

Babel's docs on arrow functions in ES6 React components shows longer examples.

score:-3

You need to assign the arrow function, below is the correct syntax for creating a named arrow function.

const showAll = () => {
  this.setState({
    showAll: true,
    showBtn: false
  });
}

Related Query

More Query from same tag