Skip to content
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

Closed
johncmunson opened this issue May 6, 2021 · 9 comments
Labels
Resolution: Stale Automatically closed due to inactivity Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug

Comments

@johncmunson
Copy link

johncmunson commented May 6, 2021

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!

@johncmunson johncmunson added the Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug label May 6, 2021
@martdavidson
Copy link

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!

@Samuel-Therrien-Beslogic

+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.

@stale
Copy link

stale bot commented Jan 9, 2022

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!

@stale stale bot added the Resolution: Stale Automatically closed due to inactivity label Jan 9, 2022
@palfrey
Copy link

palfrey commented Jan 9, 2022

Bump

@stale stale bot removed the Resolution: Stale Automatically closed due to inactivity label Jan 9, 2022
Copy link

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!

@github-actions github-actions bot added the Resolution: Stale Automatically closed due to inactivity label Apr 10, 2024
@palfrey
Copy link

palfrey commented Apr 10, 2024

Bump

@github-actions github-actions bot removed the Resolution: Stale Automatically closed due to inactivity label Apr 11, 2024
Copy link

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!

@github-actions github-actions bot added the Resolution: Stale Automatically closed due to inactivity label Jul 10, 2024
Copy link

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!

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Jul 17, 2024
@Samuel-Therrien-Beslogic

Conversation was locked repository-wide to contributor only and I couldn't bump earlier this week...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: Stale Automatically closed due to inactivity Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug
Projects
None yet
Development

No branches or pull requests

4 participants