Stop Rebuilding UI

Shadcn.io is not affiliated with official shadcn/ui

React useSessionStorage Hook

React useSessionStorage hook for tab-scoped persistent state. useState API, JSON serialization, SSR safe. TypeScript ready.

Persist React state to sessionStorage with useState-like API. useSessionStorage returns value, setter, and remove function—data persists until tab closes. Auto-serializes with JSON, supports custom serializers for complex types. Syncs across same-tab instances via custom storage events. Returns initial value during SSR. Handles errors gracefully—falls back to initial value if sessionStorage is unavailable or corrupted. Perfect for form drafts, wizard progress, temp filters, or any session-scoped UI state. Works with Next.js App Router, SSR frameworks, and incognito mode. TypeScript generics for type-safe storage. Clears automatically when tab/window closes.

React useSessionStorage Hook preview

Scroll to load preview

Installation

FAQ

Was this page helpful?

Sign in to leave feedback.