react/no-will-update-set-state
eslint-plugin-react
No autofix
eslint.config.js
import react from "eslint-plugin-react";
export default [
{
plugins: { react },
rules: {
"react/no-will-update-set-state": "error",
},
},
];var Hello = createReactClass({
componentWillUpdate: function() {
this.setState({
name: this.props.name.toUpperCase()
});
},
render: function() {
return <div>Hello {this.state.name}</div>;
}
});var Hello = createReactClass({
componentWillUpdate: function() {
this.props.prepareHandler();
},
render: function() {
return <div>Hello {this.props.name}</div>;
}
});var Hello = createReactClass({
componentWillUpdate: function() {
this.prepareHandler(function callback(newName) {
this.setState({
name: newName
});
});
},
render: function() {
return <div>Hello {this.props.name}</div>;
}
});Examples from the ESLint documentation.
react/no-will-update-set-state
eslint-plugin-react
import react from "eslint-plugin-react";
export default [
{
plugins: { react },
rules: {
"react/no-will-update-set-state": "error",
},
},
];react/no-will-update-set-state
react plugin · correctness
{
"plugins": [
"react"
],
"rules": {
"react/no-will-update-set-state": "error"
}
}Biome does not have this rule.
Enforce class component state initialization style
Enforce boolean attributes notation in JSX
Enforce all defaultProps have a corresponding non-required PropType
Enforce a specific function type for function components
Enforce consistent usage of destructuring assignment of props, state, and context