Answer the question
In order to leave comments, you need to log in
Why does LocalStorage.getItem return a json object before writing data to it?
There is an effect that fires when the page loads, already has some information, which does not allow me to set the conditions. Why is this happening?
useEffect(()=>{
const localStorageData = localStorage.getItem(LocalStorageName);
console.log('without auth',localStorageData)
console.log('without auth',typeof(localStorageData));
},[])
Answer the question
In order to leave comments, you need to log in
That doesn't happen. If the storage locale is really empty, then such a query will return null
.
In your case, most likely there is already an entry under this name.
This can be easily checked:
localStorage.getItem('test'); // null
localStorage.setItem('foo', 'bar')
localStorage.length // 1
localStorage.foo // bar
localStorage.getItem('foo') // bar
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question