Persistent settings
Good for cursor choice, theme choice and docs preferences.
Persists React state in localStorage with serializer hooks.
Hook
import { useLocalStorage } from "@swirski/ui";Good for cursor choice, theme choice and docs preferences.
const [cursor, setCursor, clearCursor] = useLocalStorage(
"swirski-cursor",
"bolt",
);| Prop | Type | Default | Notes |
|---|---|---|---|
keyRequired | string | - | localStorage key. |
defaultValueRequired | T | - | Fallback value. |
options.serialize | (value: T) => string | - | Custom serializer. |
options.deserialize | (value: string) => T | - | Custom parser. |
| Value | Type | Notes |
|---|---|---|
value | T | Current state, initialized from defaultValue and then hydrated from localStorage. |
setValue | Dispatch<SetStateAction<T>> | Updates React state and persists the serialized value. |
removeValue | () => void | Removes the stored item and resets state to defaultValue. |