1.0.1 • Published 6 years ago

yl-persistent-var v1.0.1

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

yl-persistent-var

Persist your data by localStorage and use it like react's state.

Recommended for use in webpack environment.

How to Use

import YlPersistentVar from 'yl-persistent-var'

// Set cache key 'custom-name'
const v = new YlPersistentVar('custom-name');
// set states
v.setState({
  a:1,
  b:2,
});
console.log(v.getState());

// set state by a function
v.setState(prevState => {
  prevState.a++;
  return prevState;
});
console.log(v.getState());

// clear your data
// v.clear();
// console.log(v.getState());

Your data will be saved by localStorage. Try run this script again.