我有以下程序代码。当运行应用程序时,我得到一个TypeError,并标记了configureStore。我做错了什么?
TypeError:baseReducer不是函数
import { combineReducers, configureStore } from "@reduxjs/toolkit";
import userReducer from "./userSlice";
import darkModeSlice from "./darkModeSlice";
import {
persistStore,
persistReducer,
FLUSH,
REHYDRATE,
PAUSE,
PERSIST,
PURGE,
REGISTER,
} from "redux-persist";
import storage from "redux-persist/lib/storage";
const persistConfig = {
key: "root",
version: 1,
storage,
};
const rootReducer = combineReducers({
user: userReducer,
mode: darkModeSlice,
});
const persistedReducer = persistReducer(persistConfig, { rootReducer });
export const store = configureStore({
reducer: persistedReducer,
middleware: (getDefaultMiddleware) =>
getDefaultMiddleware({
serializableCheck: {
ignoredActions: [FLUSH, REHYDRATE, PAUSE, PERSIST, PURGE, REGISTER],
},
}),
});
export type RootState = ReturnType<typeof store.getState>;
export type AppDispatch = typeof store.dispatch;
export const persistor = persistStore(store);
1条答案
按热度按时间2eafrhcq1#
此问题是由将
rootReducer
传递给persistReducer
函数的方式引起的。应该直接传递rootReducer
,而不是将其 Package 在对象中。更改以下行:致: