How to read value in useLocalStorage?
See original GitHub issueFirst , I use useLocalStorage
to init IS_LOGIN
in Login.vue
:
const isLogin = useLocalStorage('IS_LOGIN', true)
And then , I need read it in other pages, But I don’t konw how to read it, may be like this:
const token = useLocalStorage(key)
But it’s tip me need defalutValue
, So how to read it exactly?
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
useLocalStorage React Hook - useHooks
We bring you easy to understand React Hook code recipes so you can learn how React hooks work and feel more comfortable writing...
Read more >How to Use localStorage with React Hooks to Set and Get Items
localStorage is a web storage object that allows JavaScript sites and apps to keep key-value pairs in a web browser with no expiration...
Read more >useLocalStorage() react hook - usehooks-ts
If you just want read value from local storage, see useReadLocalStorage(). Related hooks: useSessionStorage(). The Hook.
Read more >Using localStorage with React Hooks - LogRocket Blog
In this guide, we cover how to use localStorage to persist a user's form ... retrieve the saved value, and use that value...
Read more >How to Use Local Storage with JavaScript - Section.io
This method is used to retrieve a value/string from a specific location. The index can be passed into the key() function as a...
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
^ Can this be reopened because it should do an initial fetch at least. useStorage has serializers for objects built in
@antfu
The main reason is that I need to set the value of IS_LOGIN after the login verification is completed, and then I need to get it in other pages.
I’ll use
localStorage.getItem('IS_LOGIN')
, it’s useful!Thanks!