react-set-state-usage
react-set-state-usage is a rule, that enforces usage of callbacks in setState calls instead of objects. Moreover, it forbids access to this.props
and this.state
within setState(...)
calls.
- updater-only: it also has updater-only option to forbid usage of second
callback
parameter of setState
Installation
react-set-state-usage is available as the react-set-state-usage
package on npm.
Usage
Extend this tslint plugin in the tslint.json
file and update the rules as displayed in the following code:
{ "extends": [ "react-set-state-usage" ], "rules": { "react-set-state-usage": true },}
To enable the updater-only option, rule should be used like this:
"rules:" { "react-set-state-usage": [true, "updater-only"]}
Examples