useLocalStorage default value #1203
tianhuil
started this conversation in
Feature requests
Replies: 2 comments 3 replies
-
Superjson seems nice, never heard about it before. I think we can include it in documentation, do you want to create a PR with these docs? |
Beta Was this translation helpful? Give feedback.
0 replies
-
Thanks @rtivital: here it is: master...tianhuil:patch-1 |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Naively using
useLocalStorage
withsuperjson
generates a cryptic error:Here is the code.
It turns out that this is because we are trying to deserialize an undefined value from localStorage for a new key. The problem is fairly non-obvious, especially given the unhelpful error message. Once you have the problem, a workaround is simple:
I propose we either:
superjson
as an example to showcase the trickiness of deserialization.undefined
for the user:undefined
is almost certainly means localStorage was not initialized anddefaultValue
is the intended value.Beta Was this translation helpful? Give feedback.
All reactions