Redux 持久黑名单删除减速器?

时间:2020-12-20 14:41:03

标签: javascript reactjs redux redux-saga

所以我有一个 react redux 应用程序并使用 'blacklist' 参数来不给几个减速器补水。但是,刷新时它会完全删除整个减速器,而不是将它们设置为初始状态。当不使用 redux persist 时,reducers 初始状态很好。这是商店的索引文件:

import { createStore, applyMiddleware, compose } from "redux";
import createSagaMiddleware from "redux-saga";

import rootReducer from "./reducers";
import rootSaga from "./sagas";

import thunk from "redux-thunk";
import logger from "redux-logger";

import { persistStore, persistReducer } from "redux-persist";
import storage from "redux-persist/lib/storage";
import hardSet from "redux-persist/lib/stateReconciler/hardSet";

const persistConfig = {
  key: "root",
  storage,
  stateReconciler: hardSet,
  blacklist: ["Alerts", "Layout", "JourneyData"]
};

const persistedReducer = persistReducer(persistConfig, rootReducer);

const sagaMiddleware = createSagaMiddleware();
const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;

const middleWares = [sagaMiddleware, thunk];

const store = createStore(
  persistedReducer,
  composeEnhancers(applyMiddleware(...middleWares, logger))
);

export const persistor = persistStore(store);
sagaMiddleware.run(rootSaga);

export default store;

0 个答案:

没有答案