0.0.2 • Published 6 years ago
persist-hook v0.0.2
Persist Hook
Give me a key, I'll make your hook's state persistence.
Installation
$ npm install persist-hook
Usage
import PersistHook from 'persist-hook';
// In your hook
const config = { key: '$$$normalhook' };
const normalHook = (initialValue = 0) => {
const { setPersist, getPersist } = PersistHook(config);
const [state, setState] = useState(getPersist(initialValue)); // Take the persistence state if it exists.
setPersist(state); // Synchronize between hook's state and localstorage.
return { state, setState };
};