zustand-indexeddb-storage
v1.0.0
Published
`Zustand Indexed DB Storage` is a utility library designed to enhance the state management capabilities of Zustand by persisting state in IndexedDB. This package enables seamless storage and retrieval of state across sessions and browser tabs using Indexe
Maintainers
Readme
zustand-indexeddb-storage
zustand-indexeddb-storage is a plugin for Zustand that allows you to persist your store's state in IndexedDB. This package makes it easy to maintain state across sessions and browser tabs.
Features
- Persist Zustand State in Indexed DB: Save and load Zustand state from Indexed DB automatically.
- Lightweight: Minimalistic design with a small footprint.
Installation
Install the package via npm or yarn:
npm install zustand-indexeddb-storage
# or
yarn add zustand-indexeddb-storageExample
import { create } from "zustand";
import { createJSONStorage, persist } from "zustand/middleware";
import { indexedDBStorage } from "zustand-indexeddb-storage";
const useMainStore = create(
persist(
(...args) => ({
...locationSlice(...args),
...profileSlice(...args),
}),
{
name: "main",
storage: createJSONStorage(() => indexedDBStorage),
partialize(state) {
return {
basketIds: state.basketIds
};
},
}
)
);
export default useMainStore;
