useLocalStorage
Synchronizes state with window.localStorage across tabs.
2.3 KB
•Updated on September 3, 2026
Example 2: Form Settings Object
Example 3: Persistent Todo List
Installation
Bash
pnpm dlx shadcn@latest add @spaceui/hooks-browser-use-local-storageUsage
Code
import { useLocalStorage } from '@/hooks/use-local-storage'
const [count, setCount, remove] = useLocalStorage('key', 0)API Reference
Parameters / Props
| Parameter | Type | Default | Description |
|---|---|---|---|
key | string | required | Storage key. |
initialValue | T | required | Fallback value. |
Return Value
| Return Type | Description |
|---|---|
[T, (val: T) => void, () => void] | Value, setter, and remover. |