We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
What is the current behavior? useLocalStorage sets string in string: Something like:
const [v, setv] = useLocalStorage("theme"); <button onClick={() => setv("black")}>set</button>
will set "black" to local storage, NOT black
"black"
black
As I expected, localStorage.setItem("theme", "black") will set black
localStorage.setItem("theme", "black")
They means localStorage.getItem("theme") === '"dark"' will return true but localStorage.getItem("theme") === 'dark' will return false.
localStorage.getItem("theme") === '"dark"'
true
localStorage.getItem("theme") === 'dark'
false
Steps to reproduce it and if possible a minimal demo of the problem. Your bug will get fixed much faster if we can run your code and it doesn't have extra dependencies other than react-use. Paste the link to your JSFiddle or CodeSandbox example below: https://codesandbox.io/s/react-fw-react-use-localstorage-vpu4i
react-use
What is the expected behavior?
A little about versions:
The text was updated successfully, but these errors were encountered:
That's the normal behaviour, as described here : https://github.com/streamich/react-use/blob/master/docs/useLocalStorage.md, data is serialized / deserialized before beeing sent / get back to / from local storage, and the default serializer and deserializer are JSON.stringify and JSON.parse. You can override serializer to not tranform data to JSON if you don't want tranform your data to string : https://codesandbox.io/s/react-fw-react-use-localstorage-forked-in97s?file=/src/App.tsx
JSON.stringify
JSON.parse
Sorry, something went wrong.
I understand, thanks!
No branches or pull requests
What is the current behavior?
useLocalStorage sets string in string: Something like:
will set
"black"
to local storage, NOTblack
As I expected,
localStorage.setItem("theme", "black")
will setblack
They means
localStorage.getItem("theme") === '"dark"'
will returntrue
butlocalStorage.getItem("theme") === 'dark'
will returnfalse
.Steps to reproduce it and if possible a minimal demo of the problem. Your bug will get fixed much faster if we can run your code and it doesn't have extra dependencies other than
react-use
. Paste the link to your JSFiddle or CodeSandbox example below:https://codesandbox.io/s/react-fw-react-use-localstorage-vpu4i
What is the expected behavior?
A little about versions:
react-use
: 17.3.1The text was updated successfully, but these errors were encountered: