- If you have internal state and/or refs, prefer
class extends React.Component
overReact.createClass
unless you have a very good reason to use mixins. eslint:react/prefer-es6-class
// bad
const Listing = React.createClass({
// ...
render() {
return <div>{this.state.hello}</div>;
}
});
// good
class Listing extends React.Component {
// ...
render() {
return <div>{this.state.hello}</div>;
}
}
And if you don't have state or refs, prefer arrow functions over classes:
// bad
class Listing extends React.Component {
render() {
return <div>{this.props.hello}</div>;
}
}
// good
const Listing = ({ hello }) => (
<div>{hello}</div>
);
// good
function Listing({ hello }) {
return <div>{hello}</div>;
}