@sarah_mn/use-local-storage-state
v1.0.2
Published
A simple React hook to sync state with localStorage or sessionStorage
Maintainers
Readme
use-local-storage-state
🧠 A lightweight React hook for managing persistent state using
localStorageorsessionStorage.
Installation
npm install @sarah_mn/use-local-storage-state
# or
yarn add @sarah_mn/use-local-storage-state
# or
pnpm add @sarah_mn/use-local-storage-state
Usage
import useLocalStorageState from "use-local-storage-state";
function App() {
const [name, setName] = useLocalStorageState("name", "Sarah");
return <input value={name} onChange={(e) => setName(e.target.value)} />;
}API
useLocalStorageState(key, initialValue, options?)
key— string key for storageinitialValue— default valueoptions—"local" || "session"
✨ Features
⚡ Simple React hook interface
🔒 Syncs state with
localStorageorsessionStorage🧩 TypeScript ready
🔁 Works across tabs and reloads
🌗 Supports SSR-safe defaults
Contributing
if your pull requests makes documentation changes, please update readme file.
License
MIT © Sarah_Mn
