Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

store-to-localstorage

dimaPortyanka8MIT1.0.5

creates store creator that will persist storage to separate storage

redux localstorage, localstorage, save store, save redux

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);