Custom (de)serializer for use*StorageValue hooks
New Features
Custom serializer/deserializer options for the use*StorageValue hooks.
This would allow the use of custom serialization for (local|session)Storage data instead of the default JSON.
What is the new or updated feature that you are suggesting?
- A deserializer option that will replace the default parse function for use*StorageValue
- A serializer option that will replace the default stringify funciton for use*StorageValue
Why should this feature be included?
Sometimes you need custom serialization for (local|session)Storage.
- You're already storing simple data in a simplified serialization format (e.g.
1,2,3instead of[1,2,3]). - You have non-primitive data that will not be correctly deserialized by the default JSON.parse and need to use a custom revier/replacer function.
- You are working with small binary data and need to base64 encode it instead of JSON.
react-use's useLocalStorage supports a custom (de)serializer. So it's difficult to switch to @react-hooks/web when it's missing the functionality you were using. This is a bigger deal since react-use's useSessionStorage does not support a (de)serializer. So if you want to switch something to sessionStorage but need a custom (de)serializer then you have no option.
I've written a PR for this https://github.com/react-hookz/web/pull/913.
Closed with #913