React hook for syncing state with localStorage and sessionStorage. Current version 0.5.1, stable and feature-complete. Provides two hooks: useLocalStorage and useSessionStorage, each returning a [value, setter, remover] tuple similar to useState. Values are automatically synchronized across tabs/windows via the storage event. Differentiator: simple API with no dependencies beyond React 16.8+. Ships TypeScript definitions. Low release cadence, actively maintained.
npm install react-use-storageNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows basic usage of useLocalStorage with a counter, including set, reset, and remove operations.
Use a constant or namespace for storage keys.
Guard usage with typeof window !== 'undefined' or use a dynamic import.
Check that window is defined before calling the hook, or use a safe wrapper.
Ensure the hook is always called in the same order at the top level of a React component.