-
-
Notifications
You must be signed in to change notification settings - Fork 426
New issue
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
Update useSessionStorage to support strings + add new options + add useReadSessionStorage #340
Conversation
Add new options object argument with parseAsJson, parser, serializer props
|
Someone is attempting to deploy a commit to a Personal Account owned by @juliencrn on Vercel. @juliencrn first needs to authorize it. |
|
I think this can now be closed as addressed in #439? I'll leave open so you can confirm - Thank you very much btw! |
Yes indeed! Your PR was good, I, unfortunately, worked on it before seeing your one. |
No worries at all, just happy to see the bug fixed - thanks for your hard work on this library |
Any chance that we could still bring in the |
Fixes #335
Attempts to make
useSessionStorage
less opinionated in how session storage values are stored and parsed.Changes
Add third
options
argument touseSessionStorage
:parseAsJson: boolean
- default to true, pass asfalse
when you don't want a value to be parsed usingJSON.parse
. This will fix the bug I was describing where a value has been previously set as astring
parser: (value: string | null) => T
- a custom parser if you have stored a session storage value with a custom serializer functionserializer: (value: T) => string
- a custom serializer to store values in a format different from the default behavior ofJSON.stringify
Renamed
initialValue
todefaultValue
for readabilityRemoved
undefined
value support - I can't imagine a case where this is needed over just not storing the key/value in session storage + removing this decreases complexity of the hookAdd
useReadSessionStorage
, similar touseReadLocalStorage