no-direct-mutation-state
Configuration
rslint.config.ts
Rule Details
Disallow direct mutation of this.state. State should only be updated through
setState() (or the useState setter), so React can correctly schedule a
re-render and reconcile the resulting UI. Writing to this.state directly is
allowed only inside the component's constructor, where the initial state is
being seeded.
The rule targets both ES6 class components extending Component /
PureComponent (or their pragma-qualified forms, e.g. React.Component) and
ES5 components created with createReactClass(...) (or
<pragma>.<createClass>(...)).
Examples of incorrect code for this rule:
Examples of correct code for this rule: