Skip to content

aihornmac/mobx-localstorage

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mobx-localstorage

A declarative reactive localStorage using MobX

Install

yarn add mobx-localstorage
npm i -S mobx-localstorage

Features

  • Higher performance than native getter
  • Synchronize with external changes
  • Support native APIs and MobX APIs

Usage

Same as native but can be observed by MobX

import { autorun } from 'mobx';
import localStorage from 'mobx-localstorage';

autorun(() => {
  console.log(localStorage.getItem('foo'));
});

localStorage.setItem('foo', 'bar');

// print bar

By default mobx-localstorage treats value as JSON, due to historical reasons. Since v1.2.0 user can specify custom parser and stringifier.

localStorage.configure({
  parser: x => x,
  stringify: x => String(x),
})

About

A declarative reactive localStorage using MobX

Resources

License

Stars

Watchers

Forks

Packages

No packages published