React hook for syncing state with any Storage-compatible API (localStorage, sessionStorage, custom). Current stable version is 7.0.0. Actively maintained with frequent releases. Key differentiators: supports SSR, handles cross-tab/window/iframe synchronization via the Window storage event (configurable), compatible with React 18/19 concurrent rendering, and offers a removeItem() reset method. Built-in TypeScript types. Compared to alternatives like react-use/localstorage, this library is focused, lightweight, and production-proven (used by Twitch). Peer dependencies: React >=18 and react-dom >=18.
npm install use-storage-stateNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Demonstrates useStorageState hook with defaults, React state, and a list. Shows how to persist an array of todos to localStorage.
Ensure you destructure up to three elements: const [data, setData, remove] = useStorageState(...); remove() clears the stored key and resets to default.
Upgrade to React >=18 or use use-storage-state@6 for older React.
Use unique keys prefixed by component or feature name (e.g., 'wishlist-todos').
Use functional updates: setTodos(prev => [...prev, newTodo]) instead of passing a merge function.
No fix needed; the extra render is expected. Use the `isServerRender` helper from the README if you need to detect.
import useStorageState from 'use-storage-state'
const useStorageState = require('use-storage-state')Upgrade to React >=18 or downgrade to use-storage-state@6.
Ensure each storage key is unique across your app.