New rule suggestion: no-access-state-in-setstate
See original GitHub issueThis is the same as https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-access-state-in-setstate.md
The purpose: to deny using this.state
inside this.setState
call.
Why: Given this.setState
mutates the state asynchronously it’s extremely easy to introduce a subtle bug when in 2 sequential calls one relies on a particular this.state
state. And if those this.setState
calls are in different functions and spatially not even close the problem might be really challenging to debug.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:13
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Prevent using this.state within a this.setState (react/no-access ...
It turns out that state updates may be asynchronous. React may batch multiple setState() calls into a single update for performance.
Read more >step-security/eslint-plugin-react - NPM Package Overview
React specific linting rules for ESLint. ... react/no-access-state-in-setstate, Disallow when this.state is accessed within setState.
Read more >Eslint-plugin-react NPM
If you are using the new JSX transform from React 17, ... react/no-access-state-in-setstate, Disallow when this.state is accessed within setState.
Read more >eslint-plugin-react | Yarn - Package Manager
List of supported rules ; no-did-mount-set-state, Disallow usage of setState in componentDidMount ; no-did-update-set-state, Disallow usage of setState in ...
Read more >Understanding React Component Constructor - KnowledgeHut
We must remember that the setState() method cannot be used directly in the constructor(). Use 'this.state' to assign the initial state in the ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Since #190 was reverted in #211 this issue has not been fixed.
Oh my, I already submitted a PR (#190) for this a while ago but somehow managed to link the wrong issue back then… changed that now 😃