Documentation
useLocalStorage
Persist state to localStorage with SSR-safe implementation.
Installation
pnpm add @rouf-dev/pantheon-uiUsage
"use client";
import { useLocalStorage } from "@rouf-dev/pantheon-ui";
export function ThemeDemo() {
const [theme, setTheme] = useLocalStorage('theme', 'light');
return (
<div>
<p>Current theme: {theme}</p>
<button onClick={() => setTheme('dark')}>Dark Mode</button>
<button onClick={() => setTheme('light')}>Light Mode</button>
</div>
);
}Parameters
key: localStorage key name
initialValue: Default value if key doesn't exist