react/no-set-state
eslint-plugin-react
No autofix
eslint.config.js
import react from "eslint-plugin-react";
export default [
{
plugins: { react },
rules: {
"react/no-set-state": "error",
},
},
];var Hello = createReactClass({
getInitialState: function() {
return {
name: this.props.name
};
},
handleClick: function() {
this.setState({
name: this.props.name.toUpperCase()
});
},
render: function() {
return <div onClick={this.handleClick.bind(this)}>Hello {this.state.name}</div>;
}
});var Hello = createReactClass({
render: function() {
return <div onClick={this.props.handleClick}>Hello {this.props.name}</div>;
}
});Examples from the ESLint documentation.
No tracked preset enables this rule, so it has no reach yet.
None of the tracked presets enable this rule. Turn it on with the config below.
react/no-set-state
eslint-plugin-react
import react from "eslint-plugin-react";
export default [
{
plugins: { react },
rules: {
"react/no-set-state": "error",
},
},
];react/no-set-state
react plugin · style
{
"plugins": [
"react"
],
"rules": {
"react/no-set-state": "error"
}
}Biome does not have this rule.
Ensure destructuring and symmetric naming of useState hook value and setter variables
Require all forwardRef components include a ref parameter