Skip to content

redux-persist transform that reset the persisted redux data after a specific period of time

License

Notifications You must be signed in to change notification settings

sirLisko/redux-persist-transform-expire-in

Repository files navigation

redux-persist-transform-expire-in npm Coverage Status

redux-persist transform that reset the persisted redux data after a specific period of time.

It creates in the localStorage a property with the expiration date of the redux-persist.

Every time the state is updated the expiration date is postponed.

See a live demo at https://codesandbox.io/s/redux-persist-transform-expire-in-lmj74q.

Install

npm install redux-persist-transform-expire-in

Example

import { createStore, applyMiddleware } from "redux";
import { persistStore, persistCombineReducers } from "redux-persist";
import storage from "redux-persist/lib/storage";
import expireInTransform from "redux-persist-transform-expire-in";

const reducers = {
  // your reducers
};

const expireIn = 48 * 60 * 60 * 1000; // expire in 48h
const expirationKey = "expirationKey";
const persistConfig = {
  key: "v1",
  storage,
  transforms: [expireInTransform(expireIn, expirationKey, [])],
};

const persistedReducer = persistCombineReducers(persistConfig, reducer);
export const store = createStore(persistedReducer);
export const persistor = persistStore(store);

Configuration

Attr Type Default Notes
expireIn Number none For how long the state is going to be preserved
expirationKey String 'persistencyExpiration' Key used by the localStorage
defaultValue any {} Value to which state will be cleared to

Difference with redux-persist-transform-expire

In redux-persist-transform-expire you need to add to your reducers a specific expireAt key. redux-persist-transform-expire-in is dealing with the whole state handled by redux-persist.

About

redux-persist transform that reset the persisted redux data after a specific period of time

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •