store-to-localstorage
v1.0.5
Published
creates store creator that will persist storage to separate storage
Downloads
2
Maintainers
Readme
persist-store
creates store creator that will persist storage to separate storage
Usage
import { createStore, combineReducers } from 'redux';
import persistStore from 'store-to-localstorage';
const reducer = {
module1: reducerFunction1,
module2: reducerFunction2,
module3: reducerFunction3
};
// for example you need to store only fields
// state.module1.field.field and state.module3.field
const needSaveFields = [
['module1', 'field', 'field'],
['module3', 'field']
];
let createPersistedStore = persistStore(createStore, needSaveFields)(reducer);
store = createPersistedStore(reducer);
in case if you need to store to localStorage with some other key, or maybe save to some other storage
function getStoreFromLocalStorage() {
return JSON.parse(localStorage.getItem('store')); // you can sepcify some other key
}
function saveStoreToLocalStorage(store) {
localStorage.setItem('store', JSON.stringify(store)); // you can sepcify some other key
}
let createPersistedStore = persistStore(createStore, needSaveFields, saveStoreToLocalStorage, getStoreFromLocalStorage)(reducer);