next-themes
next-themes copied to clipboard
add option to use sessionStorage instead of localStorage
Thanks! I'd like to think about how to support this better than just a boolean. I wonder if we're missing any other common storage providers that would warrant this being a generic cache
option. Or perhaps caching/syncing can be turned off entirely.
@pacocoursey, you could alternatively add a storage?: 'local' | 'session' | Storage;
prop to ThemeProvider
to allow for local/session/custom storage implementations:
// localStorage (default)
function MyApp({ Component, pageProps }) {
return (
<ThemeProvider storage="local">
<Component {...pageProps} />
</ThemeProvider>
)
}
// sessionStorage
function MyApp({ Component, pageProps }) {
return (
<ThemeProvider storage="session">
<Component {...pageProps} />
</ThemeProvider>
)
}
// Custom storage implementation
const myCustomStorage: Storage = { /* Implementation here */ };
function MyApp({ Component, pageProps }) {
return (
<ThemeProvider storage={myCustomStorage}>
<Component {...pageProps} />
</ThemeProvider>
)
}