redux-persistence-engine-localstorage

LocalStorage engine for redux-persistence

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
redux-persistence-engine-localstorage
1131.0.04 years ago4 years agoMinified + gzip package size for redux-persistence-engine-localstorage in KB

Readme

redux-persistence-engine-localstorage

LocalStorage engine for redux-persistence

Installation

npm install --save redux-persistence-engine-localstorage

Usage

Stores everything inside window.localStorage.
import createEngine from 'redux-persistence-engine-localstorage'
const engine = createEngine('my-save-key')

You can customize the saving and loading process by providing a replacer and/or a reviver.
import createEngine from 'redux-storage-engine-localstorage';

function replacer (key, value) {
  if (typeof value === 'string') {
    return 'foo';
  }
  return value;
}

function reviver (key, value) {
  if (key === 'foo') {
    return 'bar';
  }
  return value;
});

const engine = createEngine('my-save-key', replacer, reviver);

Warning: localStorage does not expose a async API and every save/load operation will block the JS thread!
Warning: This library only works on browsers that support Promises (IE11 or better)
Warning: If the browser doest not support LocalStorage, that should be handled before passing the engine to redux-persistence (see test)