question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

New rule suggestion: no-access-state-in-setstate

See original GitHub issue

This 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:closed
  • Created 5 years ago
  • Reactions:13
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
karfaucommented, Mar 19, 2019

Since #190 was reverted in #211 this issue has not been fixed.

2reactions
cheeZerycommented, Jan 16, 2019

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 😃

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found