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

useLocalStorage not updating if many components watch the same key #266

Open
merelinguist opened this issue Jun 14, 2020 · 4 comments
Open
Labels
bug Something isn't working

Comments

@merelinguist
Copy link

Description

Hey! Thanks for the awesome project. I’m having a problem where multiple calls to useLocalStorage('my-key') from different components are not staying in sync as the value changes.

Reproduction

I’ve reproduced it in this sandbox:

https://codesandbox.io/s/distracted-bash-x9k10?file=/pages/index.js

Expected behavior

If my localStorage value changes, all my components watching that value pick up the change.

Actual behavior

The hook seems to be initializing from localStorage into individual instances of useState and then never reading from localStorage again.

@merelinguist merelinguist added the bug Something isn't working label Jun 14, 2020
@kripod
Copy link
Owner

kripod commented Jun 18, 2020

Thank you for reporting!

I omitted storage watching intentionally for performance reasons. However, this seems to be a great use-case, so it should be implemented.

I’ll give it a shot during the weekend. Please keep me reminded if I would forget about it 😅

@merelinguist
Copy link
Author

@kripod Thank you so much!

@kripod
Copy link
Owner

kripod commented Jul 17, 2020

Unfortunately, I cannot allocate time for this task. There are some hard stuff I have to cope with, and I decided to work on other OSS projects of mine, as I find them more interesting.

@guifeliper
Copy link

is it something already solved? I can reproduce the same issue, can you indicate how you intentionally omitted the storage watching?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants