react/no-did-mount-set-state
eslint-plugin-react
No autofix
eslint.config.js
import react from "eslint-plugin-react";
export default [
{
plugins: { react },
rules: {
"react/no-did-mount-set-state": "error",
},
},
];var Hello = createReactClass({
componentDidMount: function() {
this.setState({
name: this.props.name.toUpperCase()
});
},
render: function() {
return <div>Hello {this.state.name}</div>;
}
});var Hello = createReactClass({
componentDidMount: function() {
this.onMount(function callback(newName) {
this.setState({
name: newName
});
});
},
render: function() {
return <div>Hello {this.state.name}</div>;
}
});var Hello = createReactClass({
componentDidMount: function() {
this.props.onMount();
},
render: function() {
return <div>Hello {this.props.name}</div>;
}
});Examples from the ESLint documentation.
react/no-did-mount-set-state
eslint-plugin-react
import react from "eslint-plugin-react";
export default [
{
plugins: { react },
rules: {
"react/no-did-mount-set-state": "error",
},
},
];react/no-did-mount-set-state
react plugin · correctness
{
"plugins": [
"react"
],
"rules": {
"react/no-did-mount-set-state": "error"
}
}Biome does not have this rule.
Disallow JSX prop spreading the same identifier multiple times
Enforce sandbox attribute on iframe elements