How to properly use useLocalStorageValue with null values #1329
Unanswered
LordZardeck
asked this question in
Q&A
Replies: 1 comment 1 reply
|
|
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment

Uh oh!
There was an error while loading. Please reload this page.
Currently, working with
useLocalStorageValueis frustrating as it specifically disables setting a value tonull, yet forcesnullto be a type the value can be. It also forcesundefinedto be a type value can be. I can understand the reasoning of not wanting to allow null for JSON parse/stringify reasons as mentioned in the docs, but I feel like it needs to be consistent. Since I'm setting my own parse/stringify, I was able to get null to be a valid value, but now it's forcingundefinedto be an option, event if I setinitializeWithValueto true. So in order for my types to be correct, I have to wrap the hook with a custom hook that coalesces the value to null if undefined. What's the reasoning behind forcing both null and undefined?All reactions