我使用的是redux预器,但是当不设置任何中间件时,我会出现后续错误。
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>;你能帮我找出我哪里出了问题吗谢谢提前
发布于 2022-09-15 15:07:55
似乎您已经从还原器启动了中间件,应该是在之后:
export const store = configureStore({
reducer: {
combineReducers,
},middleware: (getDefaultMiddleware) => getDefaultMiddleware().concat(logger),
});https://stackoverflow.com/questions/73711568
复制相似问题