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

Package detail

redux-session-manager

ssilve198919MIT1.0.3

Persistent Redux Store using browser session storage

redux, state management, session, session storage, redux storage, persistent state, redux state, serialize

readme

redux-session-manager

Travis npm package Coveralls

Installation

npm i -S redux-session-manager

Usage

Create a persistent store by enchancing createStore

import persistState from 'redux-session-manager';
import { createStore, compose } from 'redux';
const createPersistentStore = compose(persistState(options))(createStore);
// Pass along the same arguments you would have to createStore
const store = createPersistentStore(reducers, preloadedState);

Applying enhancers

To apply enhancers, like applyMiddlware, pass it to the left of persistState in compose

const persistentStoreWithMiddleware = compose(
    applyMiddleware(...middlware),
    persistState(options)
)(createStore)

ImmutableJS

If you are using ImmutableJS via redux-immutable for example, just change the import to

import persistState from 'redux-session-manager/lib/immutable';

Options

Property Type Required? Description
name string yes This will be the key in sessionStorage for the serialized state
exclude array[string|array] no An array containing either a string representing the reducer to exclude, or an array of [reducerName, keyPaths] where keyPaths can be either a string for a direct property of the reducer, or an array representing the keyPath to the property to be excluded.

Excluding parts of state

Use the exclude option to specify which properties you do not want to serialize to the store

Example

Here is an example using Redux Dev Tools Extension, redux-thunk, redux-logger;

import persistState from 'redux-session-manager';
import { compose, createStore, applyMiddleware } from 'redux';
import logger from 'redux-logger';
import thunk from 'redux-thunk';
import reducers from './reducers';

const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
const middleware = [ thunk, logger ];
const createPersistentStoreWithMiddleware = composeEnhancers(
    applyMiddleware(...middleware),
    persistState({
        name: "sampleStore"
    })
)(createStore);

const store = createPersistentStoreWithMiddleware(reducers, /* preloadedState */);

changelog

Change Log

All notable changes to this project will be documented in this file. See standard-version for commit guidelines.

1.0.3 (2017-09-19)

Bug Fixes

  • persistState: Fix providing no preloadedState, but providing enhancers (a23f85a)

1.0.2 (2017-09-19)

1.0.1 (2017-09-19)

1.0.0 (2017-09-19)

0.0.0 (2017-09-19)