JSPM

redux-save-state

1.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 6
  • Score
    100M100P100Q39414F
  • License MIT

A Redux middleware which saves a snapshot of the state to localStorage

Package Exports

  • redux-save-state

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (redux-save-state) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

npm version david Build Status

redux-save-state

A redux middleware which saves a snapshot of the state to localStorage.

Usage

Example

import {createStore, applyMiddleware} from "redux";
import saveState from "redux-save-state/localStorage";
import combinedReducers from "./reducer";

const createStoreWithMiddlewares
  = applyMiddleware(saveState('appState'))(createStore);
const store = createStoreWithMiddlewares(combinedReducers);

// In React Component
store.dispatch(action);

console.log(localStorage.appState); // state as JSON string

Interface

import saveState from "redux-save-state/localStorage";

const key = "some_key_string";
const options = { ... };
const middleware = saveState(key, options);

key : String

Required. The key in localStorage to save state.

options.filter: Function(state: object) => object

default state => state. Saves the value returned by filter function.

options.debounce: Number

default 0. Delays setting the state to localStorage until debounce milliseconds have elapsed since the last time the action was dispatched. See also _.debounce.

options.callback: Function(store) => any

License

MIT