React useSessionStorage Hook: Per-Tab State That Survives Reloads (2026)
Here's a checkout flow that loses the customer at step three: function Checkout () { const [ step , setStep ] = useState ( 0 ); const [ form , setForm ] = useState < CheckoutForm > ( EMPTY_FORM ); // step 1: address, step 2: shipping, step 3: payment… } The customer fills in their address, picks a shipping option, and on the payment step the provider redirects them out to a 3-D Secure page and…
The React useSessionStorage hook offers per-tab state that persists across reloads, redirecting, and navigating away from the tab, and then disappears when the tab closes. This hook, from @reactuses/core, provides [value, setValue] tuple similar to useState, with the same functional updates. It reads the value from sessionStorage on mount, writes it back on every update, and has type T | null since calling setValue(null) removes the key.
The value is available even after a page reload or redirect within the same tab, but is lost when the tab is closed. sessionStorage is intended for top-level browsing contexts (tab or window) for one origin, surviving browser restarts and syncing between tabs. However, it does not survive browser back/forward or opening a new tab.
The hook shares the same API, serialization, and internals as useLocalStorage, so swapping the import changes the lifetime. Issues with hydration, setValue(null), custom serializers, and onError in useLocalStorage apply to useSessionStorage as well. When deciding between sessionStorage, useLocalStorage, useCookie, and useState, consider where the value should live and how long it should persist. sessionStorage is suitable for state that remains consistent across tabs, while useLocalStorage is better for values needed on the first request and shared across tabs.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.