`useLocalStorage` should sync with localStorage
See original GitHub issueClear and concise description of the problem
I am using the card code component which lets you change the code language ts
or js
. I use useLocalStorage
in my card component to get and set language to show in the card.
However, If I change the language from one card then it doesn’t get reflected in other cards until I refresh or come back from another route.
Suggested solution
useLocalStorage
can accept a arg to allow sync between instances.
Alternative
None
Additional context
No response
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn’t already an issue that request the same feature to avoid creating a duplicate.
Issue Analytics
- State:
- Created a year ago
- Reactions:5
- Comments:13 (5 by maintainers)
Top Results From Across the Web
useLocalStorage React Hook - useHooks
Sync state to local storage so that it persists through a page refresh. Usage is similar to useState except we pass in a...
Read more >Keeping React State and localStorage in sync - Thomas Derleth
One common use case that naturally arises is to keep React state and local storage in sync. Though we're building client-side applications, we ......
Read more >React sync with local storage and update dynamically
You need to mutate the previous state of the array. Try as the following: setStoredValue(prevState => [...prevState, valueToStore]);.
Read more >Sync to localStorage with React useReducer Hook
I guess we could've created our own useLocalStorage . But anyway, this is still better than having all of this code within the...
Read more >Using Local Storage in React with Your Own Custom ...
Much like the useState hook, our useLocalStorage hook will return a 2-element array. The first element will be the variable and the second...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@nolde don’t be upset. Vueuse already has a solution for you. Just use createGlobalState. Like this
@harmyderoman Ooooh that’s interesting. I’ll take a look into that! Thanks a lot mate!