Registry / testing / redux-persist-memory-storage

redux-persist-memory-storage

JSON →
library0.4.0jsnpmunverified

A memory storage adapter for redux-persist (v0.4.0, stable) that provides an in-memory store for Redux state, intended as a fallback when other storage mechanisms like localStorage or cookies are unavailable. It is commonly used in testing or for clients with restricted storage access. Deliberately limited to ephemeral storage; not for production persistence. Lightweight, zero dependencies, and simple API mirroring the redux-persist storage interface, with optional initial state and logging support.

npm install redux-persist-memory-storage
INSTALL
IMPORT
SIG · REDUX-PERSIST-MEMO
R
redux-persist-memory-storage
testingjavascriptv0.4.0
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.

MemoryStorage
import MemoryStorage from 'redux-persist-memory-storage'
const MemoryStorage = require('redux-persist-memory-storage')
Package does not export a named export; default import is required.
MemoryStorage (type)
import type { MemoryStorage } from 'redux-persist-memory-storage'
import { MemoryStorage } from 'redux-persist-memory-storage'
TypeScript users need to use 'import type' to get the type; the package does not expose a named member.
MemoryStorage as constructor
new MemoryStorage({ initialState: {}, logger: console.log })
MemoryStorage.create({ initialState: {}, logger: console.log })
MemoryStorage is a class; must be instantiated with 'new'. No static factory method exists.

Demonstrates setting up redux-persist with MemoryStorage, including a custom reducer, persist config, and dispatching an action.

import { createStore } from 'redux'; import { persistStore, persistReducer } from 'redux-persist'; import MemoryStorage from 'redux-persist-memory-storage'; const rootReducer = (state = { count: 0 }, action) => { switch (action.type) { case 'INCREMENT': return { ...state, count: state.count + 1 }; default: return state; } }; const persistConfig = { key: 'root', storage: new MemoryStorage({ initialState: { count: 0 } }) }; const persistedReducer = persistReducer(persistConfig, rootReducer); const store = createStore(persistedReducer); const persistor = persistStore(store); // Use store normally; state persists in memory for session store.dispatch({ type: 'INCREMENT' }); console.log(store.getState()); // { count: 1 }
Debug
Known issues
gotchaData is not persisted across page reloads or browser restarts; only kept in memory for the lifetime of the page.
fix
Use this only as a fallback. For production persistence, use localForage, redux-persist-cookie-storage, or AsyncStorage (React Native).
affects: >=0.0.0
gotchaMemoryStorage does not support cross-tab persistence; each tab maintains its own isolated store.
fix
If cross-tab synchronization is needed, consider a storage that uses localStorage or IndexedDB with a broadcast channel.
affects: >=0.0.0
deprecatedThe 'autoRehydrate' enhancer is deprecated in redux-persist >=5 and replaced with persistReducer/persistStore. Example imports used in older docs may fail.
fix
Use the modern persistReducer/persistStore approach as shown in the quickstart. See redux-persist migration guide.
affects: >=0.3.0
gotchaThe 'initialState' option is only applied once upon constructor call; calling setItem later does not merge with the initial state.
fix
Ensure you pre-populate the MemoryStorage with the desired keys before passing to redux-persist, or initialize store with the same initial state.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: memoryStorage.getItem is not a function
Using 'memoryStorage' directly instead of an instantiated object created with 'new'.
fix
const storage = new MemoryStorage(); persistStore(store, { storage });
Uncaught TypeError: Class constructor MemoryStorage cannot be invoked without 'new'
Trying to call MemoryStorage() as a regular function without 'new'.
fix
Use 'new MemoryStorage()' instead.
Cannot find module 'redux-persist-memory-storage'
The package is not installed or the import path is wrong.
fix
Run 'npm install redux-persist-memory-storage' and use the correct import: import MemoryStorage from 'redux-persist-memory-storage'
Upgrade
Version history
0.4.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
6
Resources
redux-persist-memory-storage — npm install redux-persist-memory-storage · libregistry