-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
useLocalStorage not updating if many components watch the same key #785
Comments
Fixes streamich#785 - useLocalStorage not updating if many components watch the same key This pull request depends on pull requests streamich#1021 streamich#979
Fixes streamich#785 - useLocalStorage not updating if many components watch the same key This pull request depends on pull requests streamich#1021 streamich#979
Fixes streamich#785 - useLocalStorage not updating if many components watch the same key This pull request depends on pull requests streamich#1021 streamich#979
Fixes streamich#785 - useLocalStorage not updating if many components watch the same key Previously pr streamich#786 addressed this issue by ensuring that other components watching the key would see new updates, however, those updates would not be rendered until something else triggered a re-render. This pr resolves that issue. This pull request depends on pull requests streamich#1021 streamich#979
Fixes streamich#785 - useLocalStorage not updating if many components watch the same key Previously pr streamich#786 addressed this issue by ensuring that other components watching the key would see new updates, however, those updates would not be rendered until something else triggered a re-render. This pr resolves that issue. This pull request depends on pull requests streamich#1021 streamich#979
Fixes streamich#785 - useLocalStorage not updating if many components watch the same key Previously pr streamich#786 addressed this issue by ensuring that other components watching the key would see new updates, however, those updates would not be rendered until something else triggered a re-render. This pr resolves that issue. This pull request depends on pull requests streamich#1021 streamich#979
Fixes streamich#785 - useLocalStorage not updating if many components watch the same key Previously pr streamich#786 addressed this issue by ensuring that other components watching the key would see new updates, however, those updates would not be rendered until something else triggered a re-render. This pr resolves that issue. This pull request depends on pull requests streamich#1021 streamich#979
Any news on this issue? The problem is still here. Could I help making this fix released? Here is a sandbox reproducing the problem: https://codesandbox.io/s/peaceful-hopper-l3ksy?file=/src/App.tsx |
Looks like it got merged into v14.0 which isn't on Also the unit test that specifically checks against this ticket is commented out. https://github.com/streamich/react-use/blob/v14.0/tests/useLocalStorage.test.ts#L86 |
Fixes streamich#785 - useLocalStorage not updating if many components watch the same key Previously pr streamich#786 addressed this issue by ensuring that other components watching the key would see new updates, however, those updates would not be rendered until something else triggered a re-render. This pr resolves that issue. This pull request depends on pull requests streamich#1021 streamich#979
Fixes streamich#785 - useLocalStorage not updating if many components watch the same key Previously pr streamich#786 addressed this issue by ensuring that other components watching the key would see new updates, however, those updates would not be rendered until something else triggered a re-render. This pr resolves that issue. This pull request depends on pull requests streamich#1021 streamich#979
Dang. I was hoping to replace a use of https://github.com/astoilkov/use-local-storage-state with this. Guess I won't be doing that. |
If anyone interested it is implemented in upcoming hook of |
Nice one @xobotyi — when I saw your comment at first (not knowing who you were) I thought "oh dear, somebody with yet another hook library promoting it here instead of contributing" but then I looked into it and saw what you're doing with react-hooks/web and your long history with react-use, and your reasons for leaving/starting afresh there. I'll definitely give react-hooks a try, and I expect I'll be eagerly watching its growth. Unfortunately my JS/TS expertise is more "consumer" than "contributor", else I'd get involved — hope you get the support you need! |
This hook remains unusable except in simple cases. |
There are still issues with this hook not syncing correct values when watching the same key in multiple components |
Here looking at this in 2023 and it's still not resolved. Having to use https://github.com/astoilkov/use-local-storage-state instead. Please fix this issue or remove the functionality. |
This hook is still broken, there's no |
Note: I'm already working on a PR for this.
What is the current behavior?
Multiple calls to
useLocalStorage('myKey')
from different components are not staying in sync as the value changes.Steps to reproduce it and if possible a minimal demo of the problem.
Seems that all the Sandboxes are failing to install
react-use
right now but slap this somewhere and the problem will become apparent:Basically it's initializing from localStorage into individual instances of
useState
and then never reading from localStorage again, so if it's changed out from under you... (1) you never see the update and (2) if you update it you clobber whatever was there before.What is the expected behavior?
If my localStorage value changes, all my components watching that value pick up the change.
The text was updated successfully, but these errors were encountered: