0.0.10 • Published 9 months ago
next-super-storage v0.0.10
npm i next-super-storage
yarn add next-super-storage
pnpm i next-super-storage
import { Storage } from 'next-super-storage'
export const {
useStorageContext: useCookieStorageContext,
useStorageValue: useCookieStorageValue,
StorageContextProvider,
proxyStorage: proxyCookieStorage,
Context,
} = new Storage({
type: 'cookies',
zodSchema: z.object({ colorTheme: colorThemeZodSchema }),
})
const cookieStorage = proxyCookieStorage()
const colorTheme = cookieStorage['colorTheme']
const [value, setValue] = useCookieStorageValue('colorTheme')
const { setStorage, storage } = useCookieStorageContext()
useEffect(() => {
console.log(storage.colorTheme)
}, [storage])
const onChange = () => {
setStorage((prev) => (prev.colorTheme === 'dark' ? { colorTheme: 'light' } : {}))
setValue('dark')
setValue((prev) => (prev === 'dark' ? 'light' : 'dark'))
}
<StorageContextProvider initialData={initialSSRCookies}>{children}</StorageContextProvider>