JS.REACT.PREFER.ES6.CLASS

Enforce ES5 or ES6 class for React Components

React offers you two ways to create traditional components: using the ES5 create-react-class module or the new ES6 class system. This rule allows you to enforce one way or another.

Rule Options

Copy
...
"react/prefer-es6-class": [<enabled>, <mode>]
...

always mode

Will enforce ES6 classes for React Components. This is the default mode.

Examples of incorrect code for this rule:

Copy
var Hello = createReactClass({
  render: function() {
    return <div>Hello {this.props.name}</div>;
  }
});

Examples of correct code for this rule:

Copy
class Hello extends React.Component {
  render() {
    return <div>Hello {this.props.name}</div>;
  }
}

never mode

Will enforce ES5 classes for React Components.

Examples of incorrect code for this rule:

Copy
class Hello extends React.Component {
  render() {
    return <div>Hello {this.props.name}</div>;
  }
}

Examples of correct code for this rule:

Copy
var Hello = createReactClass({
  render: function() {
    return <div>Hello {this.props.name}</div>;
  }
});

The content on this page is adapted from the ESLint User Guide. Copyright © OpenJS Foundation and other contributors, www.openjsf.org. All rights reserved. https://eslint.org/docs/rules/