useLocalStorage
HookuseState-like hook that persists values to localStorage with JSON serialisation. SSR-safe — reads on client mount. Handles serialisation errors silently.
core/use-local-storageInstallation
1 · Add registry to components.json
2 · Install component
Examples
Persistent counter
The count survives page reloads.
API Reference
| Prop | Type | Default | Description |
|---|---|---|---|
keyreq | string | — | localStorage key. |
initialValuereq | T | — | Default value when key is absent. |
(returns) [value, setValue] | [T, Dispatch] | — | Identical API to useState but persisted. |