Registry / storage / redux-persist-expire

redux-persist-expire

JSON →
library1.1.1jsnpmunverified

Transformer for redux-persist to add expiration to persisted reducer state. Current stable version 1.1.1, no recent releases. Allows setting expiry per reducer key with auto-expire, custom key for timestamp, and fallback state. Simple API compared to alternatives like redux-persist-immutable or custom middleware. Ships TypeScript types. Lightweight, no extra dependencies.

npm install redux-persist-expire
INSTALL
IMPORT
SIG · REDUX-PERSIST-EXPI
R
redux-persist-expire
storagejavascriptv1.1.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

expireReducer
import expireReducer from 'redux-persist-expire'
const { expireReducer } = require('redux-persist-expire')
Package is CommonJS; named export is actually default export.
expireReducer (CommonJS)
const expireReducer = require('redux-persist-expire')
const { expireReducer } = require('redux-persist-expire')
CommonJS require returns the default export directly, not as named.
expireReducer (named import mistake)
import exp from 'redux-persist-expire'
import { expireReducer } from 'redux-persist-expire'
Named export 'expireReducer' does not exist; use default import.

Shows how to create an expiring transform for a reducer key using redux-persist.

import expireReducer from 'redux-persist-expire'; import { persistReducer, persistStore } from 'redux-persist'; import { createStore } from 'redux'; const rootReducer = (state = {}, action) => state; const persistedReducer = persistReducer({ key: 'root', storage: require('redux-persist/lib/storage').default, transforms: [ expireReducer('preference', { expireSeconds: 3600, expiredState: { viewType: 'list' }, autoExpire: true }) ] }, rootReducer); const store = createStore(persistedReducer); const persistor = persistStore(store);
Debug
Known issues
gotcharequire('redux-persist-expire') returns the function directly, not an object with named export.
fix
Use default import: import expireReducer from 'redux-persist-expire' or const expireReducer = require('redux-persist-expire').
affects: >=1.0.0
gotchaIf `persistedAtKey` is not set and `autoExpire` is false, the transformer will not correctly track persist time.
fix
Either set `persistedAtKey` in your reducer or set `autoExpire: true`.
affects: >=1.0.0
gotchaThe `expiredState` must match the shape of the reducer state; otherwise, you may get unexpected results.
fix
Provide the initial state of the reducer as `expiredState`.
affects: >=1.0.0
gotchaDoes not work with redux-persist v5 due to API changes in transforms.
fix
Use redux-persist v4 or v6.
affects: >=1.0.0
gotchaThe transformer only applies during rehydration; changes after rehydration are not auto-expired unless `autoExpire` is true.
fix
Set `autoExpire: true` to expire on subsequent rehydrations.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: (0 , _reduxPersistExpire.default) is not a function
Using named import instead of default import in ESM.
fix
Change to: import expireReducer from 'redux-persist-expire'
expireReducer is not a function
Using destructured require incorrectly: const { expireReducer } = require('redux-persist-expire')
fix
Use: const expireReducer = require('redux-persist-expire')
Cannot read property '__persisted_at' of undefined
Missing `persistedAtKey` in reducer state or `autoExpire` not set when key is missing.
fix
Ensure your reducer sets the timestamp key (default '__persisted_at') or set autoExpire: true.
Upgrade
Version history
1.1.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
26 hits · last 30 days
node
20
Amazon
1
OpenAI (training)
1
Resources
redux-persist-expire — npm install redux-persist-expire · libregistry