Skip to content

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

@merelinguist

Description

@merelinguist

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions