0.0.2 • Published 6 years ago

persist-hook v0.0.2

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

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 };
};
0.0.2

6 years ago

0.0.1

6 years ago