@sparkyflash/redux-persist-store

1.0.10 • Public • Published

@sparkyflash/redux-persist-store

@sparkyflash/redux-persist-store is allow you to achieve persist redux store.

Current Version

1.0.10

Install

npm

npm install --save @sparkyflash/redux-persist-store

Quick Start

2 Easy Steps

1. Initiating persistState to the redux store. By default sessionStorage will be considered for storage.

import { createStore as reduxCreateStore, applyMiddleware } from "redux";
import thunk from "redux-thunk";
import app from "../reducers";
import { persistState } from "@sparkyflash/redux-persist-store";

const createStore = () =>
  reduxCreateStore(app, persistState(), applyMiddleware(thunk));

export default createStore;

Even you can pass options to persistState to specify the storage. It is flexible to inject any ecryption/serialization algorithm in encryption property.

import { createStore as reduxCreateStore, applyMiddleware } from "redux";
import thunk from "redux-thunk";
import app from "../reducers";
import { persistState } from "@sparkyflash/redux-persist-store";
const persistOptions = {
  storage: sessionStorage,
  encryption: {
    encrypt: (data) => {
      return data;
    },
    decrypt: (data) => {
      return data;
    },
  },
};

const createStore = () =>
  reduxCreateStore(app, persistState(persistOptions), applyMiddleware(thunk));

export default createStore;

2. Wrapping the component with PersistWrapper.

import React from "react";
import { Provider } from "react-redux";
import createStore from "./createStore";
import { PersistWrapper } from "@sparkyflash/redux-persist-store";

export default ({ element }) => (
  <Provider store={createStore()}>
    <PersistWrapper>{element}</PersistWrapper>
  </Provider>
);

Package Sidebar

Install

npm i @sparkyflash/redux-persist-store

Weekly Downloads

0

Version

1.0.10

License

none

Unpacked Size

27.7 kB

Total Files

14

Last publish

Collaborators

  • sparkyflash