persist-redux
Persist a Redux/RTK store with @stainless-code/persist (persistStore + persistableReducer). Use when wrapping the root reducer for hydrate SET actions, or migrating off redux-persist.
- License 许可
- MIT
- 最近更新
- 2026-11-01
- Stars
- ★ 5
- Forks
- 0
01 前言 Front Matter
- name
- persist-redux
- license
- MIT
- sources
- [ "stainless-code/persist:src/adapters/sources/redux.ts", "stainless-code/persist:docs/architecture.md" ]
- metadata
- { "type": "composition", "library": "@stainless-code/persist", "framework": "redux", "library_version": "0.4.1" }
- description
- Persist a Redux/RTK store with @stainless-code/persist (persistStore + persistableReducer). Use when wrapping the root reducer for hydrate SET actions, or migrating off redux-persist.
03 SKILL.md 正文
Persisting Redux / RTK
@stainless-code/persist/sources/redux has no native setState — hydrate dispatches a private @stainless-code/persist/SET action. The root reducer must be wrapped with persistableReducer so that action replaces state.
When to use this skill
- Classic
reduxor@reduxjs/toolkitconfigureStore/createStore. - Migrating off
redux-persistwhile keeping one Persist stack across the app.
Install
bun add @stainless-code/persist redux
# and/or
bun add @reduxjs/toolkit
redux >=5 is the optional peer (covers classic + RTK stores).
Minimal wiring
import { createStore } from "redux";
import { createJSONStorage } from "@stainless-code/persist";
import {
persistStore,
persistableReducer,
} from "@stainless-code/persist/sources/redux";
const store = createStore(persistableReducer(rootReducer));
const persist = persistStore(store, {
name: "app:root:v1",
storage: createJSONStorage(() => localStorage),
});
RTK: pass reducer: persistableReducer(rootReducer) (or wrap the combined root) into configureStore.
persistableReducer (required)
- Wrap the root only — not each slice, not leaves inside
combineReducers. - Per-slice wrap corrupts hydrate (payload is the full root state).
- Without the wrap, hydrate no-ops; in DEV Persist
console.warns if state identity is unchanged after the SET dispatch. - Named
persistableReducerto avoid clashing with redux-persist'spersistReducer.
Common mistakes
- Forgetting
persistableReducer. Silent no-op hydrate. - Wrapping slices. Full-state SET payload won't match slice shape.
replaceReducerfor hydrate. Not the Persist path.- Name clash with redux-persist
persistStore. Alias one import.
API surface
persistableReducer(baseReducer) → ReducerpersistStore(store, options) → PersistApi- Options /
PersistApi: same aspersistSource
See also: persist-zustand for a store API with native setState (no reducer wrap).
04 同仓库更多 Skills
vue-persist
Gate Vue 3 UI on Persist hydration with useHydrated (shallowRef). Use in setup/effectScope when avoiding flash of default state on async backends.
svelte-store-persist
Gate Svelte store-based UI on Persist hydration with hydratedStore (Readable). Use for Svelte 3–4 or Svelte 5 apps that still use stores; runes UI → svelte-persist.
svelte-persist
Gate Svelte 5 runes UI on Persist hydration with hydratedRune (.current). Use for Svelte 5; for stores / Svelte 3–4 use svelte-store-persist.
solid-persist
Gate Solid UI on Persist hydration with useHydrated (Accessor). Use when avoiding flash of default state on async backends; read hydrated() in reactive scopes.
react-persist
Gate React UI on Persist hydration with useHydrated + toHydrationSignal. Use when avoiding flash of default state on async backends (IndexedDB), SSR snapshot true, or wiring HydrationSignal into React 18/19.
preact-persist
Gate Preact UI on Persist hydration with useHydrated (preact/compat useSyncExternalStore). Use when avoiding flash of default state on async backends or wiring HydrationSignal into Preact.