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

NameTypeDescriptionDefault
keystringlocalStorage key.-
initialValueanyValue used when key absent or in SSR.-

Returns

NameDescription
[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.
Saha UI - The Modern React Component Library