Urgent.News

One page, thousands of outlets. See who else covered it.

Editions

Tech

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.

Read the original at dev.to →

More in Tech

Ask the machine what it is before you change it

I spent today on a control plane that provisions plain VMs over SSH — the kind of app where a wrong answer doesn't render badly, it reinstalls a database daemon on a machine that's serving traffic.

IDF Unit 8200 Alumni Association uses network to drive Israeli innovation, start-ups

The event comes as artificial intelligence and other emerging technologies are reshaping the technology sector and forcing companies and professionals to adapt to new realities.

  • Over 1,200 Unit 8200 alumni to attend annual conference in Tel Aviv
  • Association focuses on innovation, adapting to new technologies
  • Companies like Zafran, Zenity, and Bank Hapoalim expected to participate

More from Monday 17 August →