State Management
useLocalStorage
Sync state with browser localStorage with automatic serialization and updates.
import { useLocalStorage } from "saha-ui"Uses
Synchronize state with `localStorage` with SSR-safe initialization, serialization and cross-tab updates.
Props
| Name | Type | Description | Default |
|---|---|---|---|
| key | string | localStorage key. | - |
| initialValue | any | Value used when key absent or in SSR. | - |
Returns
| Name | Description |
|---|---|
| [storedValue, setValue, removeValue] | Current value, setter (accepts value or updater function), and removal function. |
Example
const [theme, setTheme, removeTheme] = useLocalStorage('theme', 'light');Notes
Listens for storage events to keep multiple tabs in sync; returns initial value during SSR.