A React hook that synchronizes state with localStorage. Current version 3.5.3 provides a simple useState-like API with automatic persistence. The library has evolved through breaking changes in v3.0.0 (type changes) and v3.4.0 (cross-tab synchronization). Requires React >=16.8.1. Ships TypeScript types. Key differentiator: minimal abstraction over native localStorage, no dependencies beyond React.
npm install react-use-localstorageNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows basic usage of useLocalStorage hook for persisting a string value to localStorage.
Update any custom types or callbacks expecting (value: string) => void to accept React.Dispatch<string>.
Use type inference or update TypeScript definitions accordingly.
Use a wrapper that conditionally calls useLocalStorage only when window is available (see README).
Manually JSON.stringify/parse values or use a library that supports arbitrary types.
Upgrade to >=3.4.0 to avoid potential stale state issues.
Use a different hook if you want to control synchronization behavior.
Instantiate only in browser: const useSsrLocalStorage = (key, initial) => typeof window === 'undefined' ? [initial, () => {}] : useLocalStorage(key, initial);Change import to: import useLocalStorage from 'react-use-localstorage'
Run: npm install react-use-localstorage
Update React to >=16.8.1: npm install react@latest react-dom@latest