-
Notifications
You must be signed in to change notification settings - Fork 47k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature Request: ESLint hooks rule for accessing previous state when deriving new state #21448
Comments
Got bitten by this last week, and it was especially nefarious as it only showed as an issue in production when built, not in local development. Would love to see a rule for this! |
+1 on this. Took me a while to realise my state update was wrong just because I forgot to use the function. Could probably even be auto-fixable. |
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! |
Bump |
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! |
Bump |
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! |
Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please create a new issue with up-to-date information. Thank you! |
Conversation was locked repository-wide to contributor only and I couldn't bump earlier this week... |
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!
The text was updated successfully, but these errors were encountered: