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

When calling setState multiple times, only the last call takes effect #55

Open
phparkle opened this issue Jun 21, 2021 · 1 comment
Open

Comments

@phparkle
Copy link

phparkle commented Jun 21, 2021

With React's useState hook, you can call setState multiple times and it will queue the updates, as long as you are passing a function to setState. However, in this library only the last call will take effect while all other calls will be effectively ignored.

Fortunately this is implemented properly in https://github.com/astoilkov/use-local-storage-state so you can use that library instead if you are running into this issue.

@lcampanis
Copy link

lcampanis commented Apr 30, 2022

I can confirm the issue.

When hooks run for the first time, setting the value in localStorage will indeed set it, but will return the previous value to the other views, so the other views will never get the latest value which was just set.

The alternative works as expected. https://github.com/astoilkov/use-local-storage-state

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

2 participants