bring-shrubbery / use-cookie-consent

Smol (~1kB gzipped) hook for managing GDPR cookie consent state.
https://use-cookie-consent.js.org
MIT License
403 stars 15 forks source link

Add support for `Storage` API #10

Closed bring-shrubbery closed 2 years ago

bring-shrubbery commented 3 years ago

Is your feature request related to a problem? Please describe. Currently there's no way of changing where consent is being stored, nor there is a way to manage multiple storage options.

Describe the solution you'd like Add web Storage API support, which would allow using anything for storing consent, including LocalStorage, SessionStorage, or a custom implementation, you could even implement it to store it on a server.

Example usage from user's perspective

User should be able to write following code to save things into localStorage instead of cookies:

const data = useCookieConsent({
  storage: localStorage
});

Or following to save it in sessionStorage:

const data = useCookieConsent({
  storage: sessionStorage
});

Or a custom Storage:

const data = useCookieConsent({
  storage: {
    getItem: () => ...,
    setItem: () => ...,
    etc...
  }
});