@ludens-reklame/preserve
v2.0.8
Published
A handy localstorage util
Downloads
4
Keywords
Readme
Preserve
A state lib for keeping track of and change localStorage data
Install
npm install @ludens-reklame/preserve
or with Yarn
yarn add @ludens-reklame/preserve
Basic usage
import preserve from '@ludens-reklame/preserve';
// Make an item you want to keep track of.
const myItem = preserve('myData');
// Get the current data from localStorage
myItem.get();
// Update the localStorage data.
myItem.set(2);
// Listen to changes that happens within your localStorage item
myItem.subscribe(nextData => {
console.log(nextData); // 2
});
// Clear the item from localStorage
myItem.clearItem();