local-storage
local-storage copied to clipboard
Could accept custom storage
It would be damn cool if this library accepted as config a custom storage, compliant to the Storage spec. This would not only cover session storage usage, but also any other possibility of storage.
Hey @lucasconstantino do you have an example of other Storage interfaces you'd like to use?
Initial thoughts on API might include a provider (not the best) or a third argument to the hook.
// either
<StorageProvider store={window.sessionStorage || window.localStorage || window.IndexedDB.open()}>
...
</StorageProvider>
// or
useStorage('key', initialValue, window.sessionStorage || window.localStorage || window.IndexedDB.open())
In the latter case, it is almost worth creating a separate hook as software should do one thing and one thing well. Also see