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

Breaking rules of hooks leads to incorrect behaviour in useLocalStorage #2553

Open
midas-myth opened this issue Apr 4, 2024 · 0 comments
Open

Comments

@midas-myth
Copy link

typeof valOrFunc === 'function' ? (valOrFunc as Function)(state) : valOrFunc;

When function updater is called, its called with state, that is not guaranteed to be fresh. Original react setState, guarantees that prevValue is updater function is latest. This breaks when there are simultaneous setState calls. The state passed to second, third and so on updater functions are not reflecting previous changes.

Maybe ref could do here ?

@midas-myth midas-myth changed the title Breaking rules of hooks leads to incorrect behaviour Breaking rules of hooks leads to incorrect behaviour in useLocalStorage Apr 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant