Warning: Can't perform a React state update on an unmounted component.

Warning: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in a useEffect cleanup function.
原因就是报错中所说:无法对已卸载的组件执行react状态更新。

假设现在我们正在A页面调接口请求数据,请求成功后setState()更新数据,这是没有问题的。

但是如果A页面在请求接口途中,切换路由跳转至B页面,这时候A页面的数据请求还在进行中,等到数据返回的时候,调用setState()发现A组件被卸载了,就会抛出以上异常。

posted @   Arborblog  阅读(458)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
点击右上角即可分享
微信分享提示