localStorage.getItem() : Could not fetch any data in form the local storage by the key

Viewed 48

I could not fetch any data in form the local storage by the key but data is there with the associate key in react js. Please help me. All time it giving me null return value

2 Answers

Store the item from the place you want like this

localStorage.setItem("sample", "1234567");

and receive the item like this where you want

localStorage.getItem("sample")

Sorry i fixed the issue. the problem is i set the value with the key named 'token:' and while calling the value from local storage i was always calling it with 'token'. So that's why i did not get the value first

Related