A custom hook to synchronize the state value with localStorage
npm install use-local-state-hook---
---
bash
npm install use-local-state-hook
`---
Usage:
`js
import { useLocalState } from "use-local-state-hook";// inside the component
const [state, setState] = useLocalState("key", "initial-value");
`---
Example:
`js
import { useLocalState } from "use-local-state-hook";export default function App() {
const [value, setValue] = useLocalState("myKey", "", (invalidValue) => {
console.error("Cannot store File/Blob! Saving null instead.");
});
return (
value={value ?? ""}
onChange={(e) => setValue(e.target.value)}
/>
);
}
``