Closed tayurus closed 11 months ago
values are stored as strings in localStorage
you have to parse the value recieved from localStorage using JSON.parse function
eg: console.log( "my-app:count with localStorage.getItem = ", JSON.parse(localStorage.getItem("my-app:count")) );
I have created codesandbox playground for this issue https://codesandbox.io/s/cold-sun-tm82rc?file=/App.js:0-674
values are stored as strings in localStorage you have to parse the value recieved from localStorage using JSON.parse function eg:
console.log( "my-app:count with localStorage.getItem = ", JSON.parse(localStorage.getItem("my-app:count")) );
I have created codesandbox playground for this issue https://codesandbox.io/s/cold-sun-tm82rc?file=/App.js:0-674
It seems not obvious. At least it needs to be described in docs - https://rooks.vercel.app/docs/useLocalstorageState
there is no need for directly taking the data from local Storage. useLocalstorageState hook will do the parsing for you automatically if you are using the state given by the hook the whole point of the hook is to use the state and and reduce your work. even though if you have an exeptional case you can still get the data by using JSON parsing that is the normal behaviour for localStorage access
A similar issue was raised in https://github.com/streamich/react-use/issues/2224 see the reply
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
I have created codesandbox playground for this issue https://codesandbox.io/s/cold-sun-tm82rc?file=/App.js:0-674
You can check console of the playground