useLocalStorage

Hook

useState-like hook that persists values to localStorage with JSON serialisation. SSR-safe — reads on client mount. Handles serialisation errors silently.

core/use-local-storage

Installation

1 · Add registry to components.json

2 · Install component

Examples

Persistent counter

The count survives page reloads.

API Reference

PropTypeDescription
keyreq
stringlocalStorage key.
initialValuereq
TDefault value when key is absent.
(returns) [value, setValue]
[T, Dispatch]Identical API to useState but persisted.