1.1.2 • Published 7 months ago

redux-persist-transform-expire-in v1.1.2

Weekly downloads
102
License
MIT
Repository
github
Last release
7 months ago

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

AttrTypeDefaultNotes
expireInNumbernoneFor how long the state is going to be preserved
expirationKeyString'persistencyExpiration'Key used by the localStorage
defaultValueany{}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.

1.1.2

7 months ago

1.1.1

10 months ago

1.1.0

4 years ago

1.0.0

5 years ago

1.0.0-0

5 years ago

0.1.0

5 years ago