1.0.2 • Published 5 years ago

redux-persist-expire-transform v1.0.2

Weekly downloads
4
License
MIT
Repository
github
Last release
5 years ago

redux-persist-expire-transform

Expired transform reducer option for redux-persist. I initiated this project to support redux-persist V.5 up

Example

import { createStore, applyMiddleware } from "redux";
import { persistStore, persistReducer } from "redux-persist";
import storage from "redux-persist/lib/storage";
import expireTransform from "redux-persist-expire-transform";
import { combineReducers } from 'redux';

const reducerWithExpiration = [
  // your reducers
  'example1','example2'
];

const allReducers = combineReducers({
    ...reducerList,
 });
 
const expireInMinutes = 24 * 60; // expire in 24h
const persistConfig = {
  key: "root",
  storage,
  transforms: [expireTransform(expireInMinutes, reducerWithExpiration)]
};

const persistedReducer = persistReducer(persistConfig, allReducers);
export const store = createStore(persistedReducer);
export const persistor = persistStore(store);

Configuration

AttrTypeDefaultNotes
expireInMinutesNumbernoneFor how long the state is going to be preserved in minutes
whitelistString[]noneArray of state's name that would like to add expiration time