JS.REACT.REQUIRE.OPTIMIZATION

Enforce React components to have a shouldComponentUpdate method

This rule prevents you from creating React components without declaring a shouldComponentUpdate method.

Rule Details

Examples of incorrect code for this rule:

コピー
class YourComponent extends React.Component {

}
コピー
createReactClass({
});

Examples of correct code for this rule:

コピー
class YourComponent extends React.Component {
    shouldComponentUpdate () {
        return false;
    }
}
コピー
createReactClass({
    shouldComponentUpdate: function () {
        return false;
    }
});
コピー
createReactClass({
    mixins: [PureRenderMixin]
});
コピー
@reactMixin.decorate(PureRenderMixin)
createReactClass({

});

Rule Options

コピー
...
"react/require-optimization": [<enabled>, { allowDecorators: [<allowDecorator>] }]
...
  • enabled: for enabling the rule. 0=off, 1=warn, 2=error. Defaults to 0.
  • allowDecorators: optional array of decorators names to allow validation.

allowDecorators

Sets the allowed names of decorators. If the variable is present in the chain of decorators, it validates

Examples of correct code for this rule:

コピー
// ['pureRender']
@pureRender
class Hello extends React.Component {}

Example

コピー
...
"react/require-optimization": [2, {allowDecorators: ['customDecorators']}]
...

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/