Loading...
Loading...
Loading...
Persist state in localStorage with JSON serialization and cross-tab sync.
Install
npx bouncekit@latest add uselocalstorageImport
import { useLocalStorage } from "@/hooks/use-local-storage.ts"import { useLocalStorage } from "@/hooks/use-local-storage"
const [theme, setTheme] = useLocalStorage("theme", "dark")
// Persists to localStorage with cross-tab sync.API Reference
| Prop | Type | Required | Description |
|---|---|---|---|
key | string | yes | The localStorage key. |
initialValue | T | yes | Default value when no stored value exists. |
Source
src/hooks/use-local-storage.ts