Skip to content

Latest commit

 

History

13 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

redux-persist-x

redux-persist-x is a lightweight and efficient persistence library for Redux, designed to keep your Redux store state in sync across multiple storage options. With a tiny bundle size of just 4KB, redux-persist-x makes it easy to persist and rehydrate your store while keeping your builds lean.

Features

  • Tiny bundle size – only 4KB!

  • Flexible storage support – integrates with IndexedDB, localStorage, and sessionStorage

  • Optimized builds with tree-shaking and minification

  • Simple API for easy persistence and rehydration of your Redux store

  • Flexible Storage Options: Supports integration with other storage modules like localStorage, sessionStorage, or custom storage solutions

  • Easy-to-Use API: Designed to mimic the functionality of redux-persist for a smooth migration experience

Installation

Install redux-persist-x via npm or yarn:

npm install redux-persist-x
# or
yarn add redux-persist-x

Usage Examples:

  1. Basic Usage
  2. [Nested Persists][coming soon]

Basic Usage

Basic usage involves adding persistReducer and persistStore to your setup.

// configureStore.js

import { configureStore, createReducer } from '@reduxjs/toolkit';
import { combineReducers } from 'redux';
import { persistReducer } from 'redux-persist-x'; // defaults to localStorage for web

import rootReducer from './reducers'

const persistConfig = {
  whiteList: ["fileReducer"],
  storageType: "localStorage" //it can be localStorage,sessionStorage and indexedDB 
  //storage:, storage can be any storages(It is optional)
  expireDate:1730298664   //end of persisiting data 
}

const persistedReducer = persistReducer(rootReducer,persistConfig)

export const store = configureStore({
  reducer: persistedReducer,
});

If you are using react, wrap your root component with PersistWrapper.

import { PersistWrapper } from "redux-persist-x";


const App = () => {
  return (
    <Provider store={store}>
      <PersistWrapper  store={store}>
        <RootComponent />
      </PersistWrapper>
    </Provider>
  );
};

API

persistReducer(reducer,config)

  • arguments
    • [config] object
      • required config: storageType
      • notable other config: whitelist, expireDate, optional storage
    • reducer function
      • any reducer will work, typically this would be the top level reducer returned by combineReducers

persistor methods

  • the persistor object is returned by persistStore with the following methods:
    • purgePersistReducer()
      • purges state from disk and returns a promise
    • pausePersistReducer()
      • pauses persistence

Storage Engines

Community & Contributing

We welcome contributions from everyone! Whether you’re fixing bugs, suggesting new features, or improving documentation, your help is greatly appreciated. If you'd like to get involved, please feel free to open issues, create pull requests, or simply reach out to discuss ideas.

For any questions or to start a conversation, you can email me directly at [shahpoori.dev@gmail.com]. Let’s build something great together!

About

persist and rehydrate a redux store

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages