astoilkov / use-local-storage-state

React hook that persists data in localStorage
MIT License
1.17k stars 41 forks source link

need guidance for using sessionStorage also #51

Closed rhythmbhiwani closed 2 years ago

rhythmbhiwani commented 2 years ago

For some of my usecase, I also need support for using sessionStorage also, but this library seems to focus only only on local-storage. Can you please guide me how can I convert it to use both local and session storage based on some parameters. I can fork the repo and change it in that repo, so that this library can focus on local storage

astoilkov commented 2 years ago

I'm working on a branch, that's mostly done, that will allow specifying a storage option. You can then pass sessionStorage to the option. You can take a look at it here: https://github.com/astoilkov/use-local-storage-state/tree/storage-option#optionsstorage.

astoilkov commented 2 years ago

I will soon post a solution for this. Thanks for the patience.

astoilkov commented 2 years ago

Done. I've published a use-session-storage-state package. This is the repo — https://github.com/astoilkov/use-session-storage-state.

Hope that helps. Closing this issue.