1.0.2 • Published 9 months ago

zustand-persist-cookie v1.0.2

Weekly downloads
-
License
ISC
Repository
github
Last release
9 months ago

zustand-persist-cookie

Demo

Demo npm.io

Installation

npm:

npm i zustand-persist-cookie

yarn:

yarn add zustand-persist-cookie

Usage

import { create } from "zustand";
import { persist, createJSONStorage } from "zustand/middleware";
import { createCookieStorage } from "zustand-persist-cookie";

export type Theme = "light" | "dark";

export type ThemeStore = {
    theme: Theme;
    setTheme: (theme: Theme) => void;
};

export const useThemeStore = create(
    persist<ThemeStore>(
        (set) => ({
            theme: "light",
            setTheme: (theme: Theme) => {
                set({ theme });
            },
        }),
        {
            name: "theme-storage",
            storage: createJSONStorage(() => createCookieStorage()),
        }
    )
);
1.0.2

9 months ago

1.0.1

9 months ago

1.0.0

9 months ago