reactive-localstorage
A reactive localStorage with no dependency
Install
yarn add reactive-localstorage
npm i -S reactive-localstorage
Features
- Emit changes from same window
- Emit external changes
Usage
Changes from reactive-localstorage
or other pages will be emitted as events
import localStorage from 'reactive-localstorage';
localStorage.on('change', (key, value) => {
console.log(`key ${key} changed to ${value}`);
});
localStorage.setItem('foo', 'bar');
You can also trigger changes manually, especially when you have other sources that manage localStorage.
localStorage.feed('foo', 'alice');
You can also use injection to override window.localStorage
import 'reactive-localstorage/lib/inject';
import localStorage from 'reactive-localstorage';
console.log(window.localStorage === localStorage);
Related Projects