Registry / storage / redux-persist-cookie-storage

redux-persist-cookie-storage

JSON →
library1.0.0jsnpmunverified

A storage adapter for redux-persist that uses cookies as the persistence medium. Version 1.0.0 is the latest. It works in both browser (with cookies-js) and Node.js (with cookie-parser or cookies), enabling universal/isomorphic apps. Key differentiator: unlike localStorage-based adapters, cookies are automatically sent with HTTP requests, making it suitable for server-side rendering scenarios. The library supports cookie expiration and domain/path options.

npm install redux-persist-cookie-storage
INSTALL
IMPORT
SIG · REDUX-PERSIST-COOK
R
redux-persist-cookie-storage
storagejavascriptv1.0.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.

CookieStorage
import { CookieStorage } from 'redux-persist-cookie-storage'
const CookieStorage = require('redux-persist-cookie-storage').CookieStorage
ESM import; CommonJS also works but use destructuring.
NodeCookiesWrapper
import { NodeCookiesWrapper } from 'redux-persist-cookie-storage'
import NodeCookiesWrapper from 'redux-persist-cookie-storage'
Named export, not default. For server-side use with the 'cookies' npm package.

Demonstrates setting up redux-persist with cookie storage in a browser environment using cookies-js and optional expiration.

// Browser: pure cookie mode import { persistStore, persistCombineReducers } from 'redux-persist'; import { CookieStorage } from 'redux-persist-cookie-storage'; import Cookies from 'cookies-js'; const persistConfig = { key: 'root', storage: new CookieStorage(Cookies, { expiration: { 'maxAge': 86400 } }), // 24h }; const rootReducer = persistCombineReducers(persistConfig, { // your reducers }); const store = createStore(rootReducer); const persistor = persistStore(store);
Debug
Known issues
gotchaCookies have a size limit (~4KB). Storing large redux state will fail silently or truncate.
fix
Only persist small state slices; use compression or limit deserialization to essential data.
affects: >=1.0.0
gotchagetStoredState will throw when the index storage item is not set (e.g., first visit). Must catch errors.
fix
Wrap getStoredState in try/catch and default to empty initial state.
affects: >=1.0.0
gotchaCookie expiration cannot be set to a past date to delete; use a short maxAge instead.
fix
For deletion, set maxAge to 0 or remove the cookie manually via cookies-js.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'get')
CookieStorage instantiated without a valid cookie jar (e.g., missing Cookies object in browser)
fix
Ensure you pass the Cookies object from 'cookies-js' (or NodeCookiesWrapper) to the constructor: new CookieStorage(Cookies)
Error: getStoredState() failed: Cookie not found (index)
No initial cookie for the persist key exists (e.g., first visit)
fix
Wrap getStoredState in try/catch and fallback to empty state: try { await getStoredState(config) } catch { preloadedState = {} }
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies
redux-persistrequiredRequired peer dependency to integrate with the redux-persist persistence framework
cookies-jsoptionalRequired in browser environment to manage browser cookies
cookiesoptionalRequired in Node.js environment to wrap server-side cookies
Agent activity
41 hits · last 30 days
node
36
OpenAI (training)
1
Resources
redux-persist-cookie-storage — npm install redux-persist-cookie-storage · libregistry