local-storage icon indicating copy to clipboard operation
local-storage copied to clipboard

Could accept custom storage

Open lucasconstantino opened this issue 6 years ago • 1 comments

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.

lucasconstantino avatar Apr 07 '19 02:04 lucasconstantino

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

mayteio avatar Jan 28 '20 19:01 mayteio