redux-persistence-engine-localstorage
v1.0.0
Published
LocalStorage engine for redux-persistence
Downloads
1,211
Maintainers
Readme
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)