question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to read value in useLocalStorage?

See original GitHub issue

First , 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:closed
  • Created 2 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
sherodtaylorcommented, Mar 3, 2022

^ Can this be reopened because it should do an initial fetch at least. useStorage has serializers for objects built in

0reactions
xieyezicommented, Jun 2, 2021

@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!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found