有没有办法禁用 Redux 警告:在状态中检测到不可序列化的值
Is there a way to disable Redux warning: A non-serializable value was detected in the state
我完全了解将不可序列化的值存储到 Redux 状态的缺点。就像 Redux docs 说的那样:
If you are okay with things like persistence and time-travel debugging potentially not working as intended, then you are totally welcome to put non-serializable items into your Redux store.
所以,我只是制作原型来尝试一些想法。我可能会在未来重构代码以从状态中消除这些函数对象,但目前这些警告只是淹没了我的控制台,埋葬了我可能真正关心的其他消息。
是否有一些开关可以切换这些警告on/off?
这是一个 redux-toolkit
错误,整个错误链接到说明如何为特定操作禁用错误的文档。
https://redux-toolkit.js.org/usage/usage-guide#working-with-non-serializable-data
引用:
However, if you do need to turnoff those warnings, you can customize the
middleware by configuring it to ignore specific action types, or fields in
actions and state:
configureStore({
//...
middleware: (getDefaultMiddleware) =>
getDefaultMiddleware({
serializableCheck: {
// Ignore these action types
ignoredActions: ['your/action/type'],
// Ignore these field paths in all actions
ignoredActionPaths: ['meta.arg', 'payload.timestamp'],
// Ignore these paths in the state
ignoredPaths: ['items.dates'],
},
}),
})
我完全了解将不可序列化的值存储到 Redux 状态的缺点。就像 Redux docs 说的那样:
If you are okay with things like persistence and time-travel debugging potentially not working as intended, then you are totally welcome to put non-serializable items into your Redux store.
所以,我只是制作原型来尝试一些想法。我可能会在未来重构代码以从状态中消除这些函数对象,但目前这些警告只是淹没了我的控制台,埋葬了我可能真正关心的其他消息。
是否有一些开关可以切换这些警告on/off?
这是一个 redux-toolkit
错误,整个错误链接到说明如何为特定操作禁用错误的文档。
https://redux-toolkit.js.org/usage/usage-guide#working-with-non-serializable-data
引用:
However, if you do need to turnoff those warnings, you can customize the middleware by configuring it to ignore specific action types, or fields in actions and state:
configureStore({
//...
middleware: (getDefaultMiddleware) =>
getDefaultMiddleware({
serializableCheck: {
// Ignore these action types
ignoredActions: ['your/action/type'],
// Ignore these field paths in all actions
ignoredActionPaths: ['meta.arg', 'payload.timestamp'],
// Ignore these paths in the state
ignoredPaths: ['items.dates'],
},
}),
})