1.1.5 • Published 7 months ago

redux-persist-x v1.1.5

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

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

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!

1.1.5

7 months ago

1.1.4

8 months ago

1.1.3

8 months ago

1.1.2

8 months ago

1.1.1

8 months ago

1.1.0

8 months ago

0.1.0

8 months ago