我正在使用redux presist,但在没有设置任何中间件时出现了以下错误
serializableStateInvariantMiddleware.ts:194 A non-serializable value was detected in an action, in the path: `register`. Value: ƒ register(key) {
_pStore.dispatch({
type: _constants__WEBPACK_IMPORTED_MODULE_0__.REGISTER,
key: key
});
当我尝试使用使用getdefault中间件的中间件来解决这个问题时,它给出了以下错误
Object is of type 'unknown'.
34 | reducer:{
35 | app:presistedReducer,
> 36 | middleware: (getDefaultMiddleware) => getDefaultMiddleware().concat(logger),
| ^^^^^^^^^^^^^^^^^^^^
37 | },
38 |
39 | })
}
Take a look at the logic that dispatched this action: {type: 'persist/PERSIST', register: ƒ, rehydrate: ƒ}
我甚至再试了一次,但这个错误
Uncaught TypeError: getDefaultMiddleware is not a function
这是我的代码store.ts
import { configureStore} from "@reduxjs/toolkit";
import storage from 'redux-persist/lib/storage';
import { combineReducers } from 'redux';
import { persistReducer,persistStore } from 'redux-persist';
import FavouriteReducer from "./FavouriteSlice";
import ProductReducer from './ProductSlice'
import ActionReducer from "./ActionSlice";
import {
FLUSH,
REHYDRATE,
PAUSE,
PERSIST,
PURGE,
REGISTER,
} from 'redux-persist'
const reducers= combineReducers({
action:ActionReducer,
favourite:FavouriteReducer,
product:ProductReducer
})
const persistConfig = {
key: 'root',
version: 1,
storage,
}
const presistedReducer=persistReducer(persistConfig,reducers)
export const store = configureStore({
reducer:{
app:presistedReducer,
middleware: (getDefaultMiddleware) =>
getDefaultMiddleware({
serializableCheck: {
ignoredActions: [FLUSH, REHYDRATE, PAUSE, PERSIST, PURGE, REGISTER],
},
}),
},
})
export const Persistor =persistStore(store)
export type AppDispatch = typeof store.dispatch;
export type RootState = ReturnType<typeof store.getState>;
你能帮我弄清楚我哪里错了吗提前感谢
您似乎已经从reducer启动了中间件,应该在:之后
export const store = configureStore({
reducer: {
combineReducers,
},middleware: (getDefaultMiddleware) => getDefaultMiddleware().concat(logger),
});