Reputation: 2048
I actively use eslint-plugin-react
and recently read about functional setState. I wanted to use eslint rule for this, but couldn't find. Is there eslint-react rule that forces to use functional setState only?
Upvotes: 2
Views: 273
Reputation: 18116
Currently, there is no such eslint-plugin-react
rule available.
There are the related GitHub issues:
setState()
if not using previous state · Issue #1836 · yannickcr/eslint-plugin-react.Please, take a look at them.
The issue #2 from the «Related issues» list — Rule Suggestion : setState function · Issue #1196 · yannickcr/eslint-plugin-react — seems to be the closest to or the same as your question (request).
The implementation-related issue: Rule idea: Disallow accessing this.state within setState · Issue #943 · yannickcr/eslint-plugin-react.
It seems the feature was implemented somewhat partially.
Partially, because:
this.state
within the setState()
argument: both object initialiser and function.this.state
in its object initialiser) as the setState()
function argument. For example:
this.setState({quantity: 2});
Please, consider reporting the details to the existing «closest» issue to make an attempt to re-open it or open a new issue.
Upvotes: 2