请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

老师,帮忙看下这个报错原因是什么?不影响程序运行,但是想解决,是在添加persist后出现的。

A non-serializable value was detected in an action, in the path: register. Value: ƒ register(key) {
pStore.dispatch({
type: constants__WEBPACK_IMPORTED_MODULE_1
[“REGISTER”],
key: key
});
}
Take a look at the logic that dispatched this action: Object
type: "persist/PERSIST"
register: ƒ register(key)
rehydrate: ƒ rehydrate(key, payload, err)
proto: Object
(See https://redux.js.org/faq/actions#why-should-type-be-a-string-or-at-least-serializable-why-should-my-action-types-be-constants)
(To allow non-serializable values see: https://redux-toolkit.js.org/usage/usage-guide#working-with-non-serializable-data)

正在回答

2回答

hello 新年快乐啊。你观察的非常仔细,这个问题是因为 Redux Toolkit 的中间件会深度检查状态树, 一旦检测到非序列化的数据则会报错。我们来看看redux tookit官网是怎么说的:https://redux-toolkit.js.org/api/getDefaultMiddleware

https://img1.sycdn.imooc.com//szimg/6026e8f809c54d5c18281606.jpg


还记得课程中怎么描述redux-persist的数据保存方式吗?我们把数据以键值对的方式保存在local storage中,而真正储存的数据是stringfy以后的字符串,当我们需要使用的时候再把string从local storage中取出来,然后再转化为对象。既然保存的数据是string,所以会有这个报错。


  • 改正方法:

getDefaultMiddleware 参数中设置 serializableCheck 为 false,报错就消失了。

https://img1.sycdn.imooc.com//szimg/6026e8f80904cf9419520682.jpg

祝你新年快乐、万事如意啊

2 回复 有任何疑惑可以回复我~
  • 提问者 文文文文礼 #1
    非常感谢!老师也新年快乐!给自己放个假哦
    回复 有任何疑惑可以回复我~ 2021-02-13 10:44:49
  • 感谢感谢
    回复 有任何疑惑可以回复我~ 2021-03-21 15:58:23
慕用4509656 2022-06-16 19:15:34

https://img1.sycdn.imooc.com//szimg/62ab107209bf79f209620574.jpg

因为redux-persist定义的action中的payload包含函数类型, redux建议payload是可序列化的。直接忽略persist的type就可以消除这个报错

0 回复 有任何疑惑可以回复我~
问题已解决,确定采纳
还有疑问,暂不采纳
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号