Registry / storage / redux-persist-indexeddb-storage

redux-persist-indexeddb-storage

JSON →
library1.0.4jsnpmunverified

A storage engine for redux-persist that leverages IndexedDB via localForage, providing asynchronous, persistent state storage for React applications. Version 1.0.4 is the latest and appears stable with no frequent releases. Key differentiators: automatic fallback to localStorage for browsers without IndexedDB support, and a simple API that integrates directly into redux-persist config. This package is a thin wrapper around localForage, which has broad browser support. Note: limited to React/browser environments and depends on redux-persist v4/v5.

npm install redux-persist-indexeddb-storage
INSTALL
IMPORT
SIG · REDUX-PERSIST-INDE
R
redux-persist-indexeddb-storage
storagejavascriptv1.0.4
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.

storage
import storage from 'redux-persist-indexeddb-storage';
import { storage } from 'redux-persist-indexeddb-storage';
Default export only; named import is incorrect.
storage (with database name)
const storage = require('redux-persist-indexeddb-storage');
import storage from 'redux-persist-indexeddb-storage'
In CommonJS, use require; may also use default import in ESM contexts.
storage() call
storage('myDB')
storage('myDB', {})
The function takes one optional argument (database name). No options object is supported.

Configures redux-persist to use IndexedDB storage via redux-persist-indexeddb-storage. Sets up a persist reducer, store, and persistor.

import storage from 'redux-persist-indexeddb-storage'; import { persistStore, persistReducer } from 'redux-persist'; import { createStore } from 'redux'; const persistConfig = { key: 'root', storage: storage('myAppDB'), }; const rootReducer = (state = { count: 0 }, action) => { switch (action.type) { case 'INCREMENT': return { count: state.count + 1 }; default: return state; } }; const persistedReducer = persistReducer(persistConfig, rootReducer); const store = createStore(persistedReducer); const persistor = persistStore(store); export { store, persistor };
Debug
Known issues
gotchaThe storage function returns a storage engine object compatible with redux-persist v4/v5 but may not work with v6. Verify compatibility.
fix
Use with redux-persist v4 or v5, or check if the package has been updated for v6.
affects: >=1.0.0
gotchaIndexedDB operations are asynchronous, so the persisted state may not be immediately available after page load. Ensure your app handles the rehydration delay.
fix
Use the PersistGate component from redux-persist to delay rendering until rehydration is complete.
affects: >=1.0.0
brokenIf the database name contains special characters or exceeds 64 characters, IndexedDB may throw errors.
fix
Use only alphanumeric characters and underscores, keep name under 64 characters.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'getItem')
The storage function was not called, e.g., passed as a reference instead of calling it.
fix
Fix: storage: storage('myDB') instead of storage: storage
Error: Invalid database name
IndexedDB database name is invalid (e.g., empty or contains invalid characters).
fix
Ensure the database name is a non-empty string using [a-zA-Z0-9_].
Uncaught (in promise) DOMException: Operation failed because the request was called on a worker that was terminated.
The page was reloaded or navigated away while IndexedDB transaction was pending.
fix
Ensure cleanup of async operations on unmount (e.g., using useEffect cleanup).
Upgrade
Version history
1.0.4latest on npm
Audit
Dependencies
localforagerequiredUsed internally to interact with IndexedDB and provide fallback to localStorage/WebSQL.
redux-persistoptionalPeer dependency required to use this storage engine.
Agent activity
21 hits · last 30 days
node
18
Resources
redux-persist-indexeddb-storage — npm install redux-persist-indexeddb-storage · libregistry