no-unsafe
Configuration
Rule Details
Disallow the legacy UNSAFE_-prefixed React lifecycle methods that are unsafe under async rendering (React 16.3+):
UNSAFE_componentWillMount— replace withcomponentDidMount.UNSAFE_componentWillReceiveProps— replace withgetDerivedStateFromProps.UNSAFE_componentWillUpdate— replace withcomponentDidUpdate.
The rule fires only when the method is declared inside a detected React component:
- An ES6 class extending
Component/PureComponent(bare or pragma-qualified, e.g.React.Component). - An object literal passed to
createReactClass(...)(or<pragma>.<createClass>(...)).
When settings.react.version is below 16.3.0 the rule disables itself entirely (the UNSAFE_ aliases were introduced in that release).
Examples of incorrect code for this rule:
Examples of correct code for this rule:
Rule Options
checkAliases (default: false)
When true, the rule additionally flags the unprefixed legacy aliases (componentWillMount, componentWillReceiveProps, componentWillUpdate) inside detected React components. The replacement suggestions are the same as for the UNSAFE_-prefixed forms.
Examples of incorrect code with { "checkAliases": true }:
Settings
This rule is influenced by the shared React settings:
settings.react.version— when below16.3.0, the rule is a no-op (default: latest).settings.react.pragma— theReactobject name used for<pragma>.Component/<pragma>.PureComponentextends matching (default:"React").settings.react.createClass— thecreateReactClassfactory name used for ES5 component detection (default:"createReactClass").