redux-persist-expire-state

1.0.3 • Public • Published

redux-persist-expire-state

Installation

yarn add redux-persist-expire-state

or

npm install redux-persist-expire-state

Usage

import { persistReducer, persistStore } from 'redux-persist';
import expireReduxState from 'redux-persist-expire-state';
 
const config = {
  expireAfter: 10 * 60 * 60, // Expiration time of 10 hours, defaults to null
  expireKey: 'persistedAt', // key to be used in the state, defaults to persistedTimestamp
  expireState: { error: null, data: []} // state to be used after persisted state expires, defaults to {}
};
 
const persistedReducer = persistReducer({
  transforms: [expireReduxState('reducer', config)] // reducerKey for which expiry is being set, add as many reducers as required
}, rootReducer);
 
const store = createStore(persistedReducer);
const persistedStore = persistStore(store);

Examples

// Reset `user` to empty object if not updated for 30 mins
expireReducer('user', {
    expireSeconds: 1800
})

Dependencies (2)

Dev Dependencies (0)

    Package Sidebar

    Install

    npm i redux-persist-expire-state

    Weekly Downloads

    7

    Version

    1.0.3

    License

    MIT

    Unpacked Size

    4.42 kB

    Total Files

    4

    Last publish

    Collaborators

    • srujithm