State Management
useSessionStorage
Sync state with browser sessionStorage for temporary data persistence.
import { useSessionStorage } from "saha-ui"Uses
Like `useLocalStorage` but uses `sessionStorage`, providing persistence for a single tab and custom (de)serializers.
Props
| Name | Type | Description | Default |
|---|---|---|---|
| key | string | sessionStorage key. | - |
| initialValue | any | Initial fallback value. | - |
| options | object | Optional `serializer/deserializer` functions. | - |
Returns
| Name | Description |
|---|---|
| [value, setValue, removeValue] | Current value, setter, and remover. |
Example
const [sessionData, setSessionData] = useSessionStorage('cart', []);Notes
Dispatches a custom event for intra-tab updates and uses `storage` event for cross-tab changes.