persist-hook

0.0.2 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i persist-hook

Weekly Downloads

1

Version

0.0.2

License

MIT

Unpacked Size

4.76 kB

Total Files

12

Last publish

Collaborators

  • realdennis