facebook / react

The library for web and native user interfaces.
https://react.dev
MIT License
229.17k stars 46.9k forks source link

Feature Request: ESLint hooks rule for accessing previous state when deriving new state #30363

Open Samuel-Therrien-Beslogic opened 3 months ago

Samuel-Therrien-Beslogic commented 3 months ago

https://github.com/facebook/react/issues/21448

A very common mistake and source of bugs in React applications is not using the updater function when deriving new state from old state.

When using class components, there is a handy lint rule for this in the eslint-plugin-react project.

However, their rule does not work for functional components that utilize useState, and they have suggested that eslint-plugin-react-hooks would be a more appropriate home for an equivalent lint rule that does work with hooks.

I've seen this mistake made countless times, and I even fall victim to it every once in awhile, so having an officially sanctioned lint rule would be amazing!

Conversation was locked so we couldn't bump the issue. Note that I'd prefer that issue be re-opened and this one here closed to keep participants, followers, upvotes, creation date, etc.

CC @martdavidson @palfrey @johncmunson, @dangerismycat, @mathieutu, @vlnguyen, @aldenquimby, @schyler-freewill, @Stephen2

github-actions[bot] commented 3 weeks ago

This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment!

Samuel-Therrien-Beslogic commented 2 weeks ago

Bump, and I'd still prefer the old issue be re-openned