我在使用Redux serializableStateInvariantMiddleware.ts:234 A non-serializable value was detected in an action, in the path:
时遇到了一个不可序列化的值错误。我尝试按照https://redux-toolkit.js.org/usage/usage-guide#working-with-non-serializable-data文档并禁用特定项目的序列化检查。但是,它不起作用。
我有一个CustomSlice切片如下:
interface CustomItem {
dateTime: Dayjs
.....
}
export interface SomeState {
customVals: Array<CustomItem>;
....
}
const initialState: SomeState = {
customVals: new Array<CustomItem>,
...
};
export const customsSlice = createSlice({
name: 'customs',
initialState,
reducers: {
updateCustoms: (state, action) => {
//using the date value here by individually extracting from customVals
},
});
我尝试配置商店忽略使用updateCustoms的非序列化检查,但仍然得到相同的错误:
import customReducer from './CustomSlice';
export const store = configureStore({
reducer: {
customs: customReducer,
},
middleware: (getDefaultMiddleware) =>
getDefaultMiddleware({
serializableCheck: {
// Ignore these action types
ignoredPaths: ['customs.customVals'], //also tried ['customs']
// Also tried ignoredActions: ['customs/updateCustoms']
},
}),
});
我可以忽略这整个切片,但不知道该怎么做。
1条答案
按热度按时间jslywgbw1#
我必须同时包含ignoredPaths和ignoredActions,以便在特定的存储条目上禁用serializableCheck,因为它不能单独使用它们中的任何一个。
在您的情况下,它应该是:
serializableCheck正在检查存储值和操作。