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.

在这里插入图片描述

原因

出现这个的情况是:有AB两个组件,A组件的异步函数还没有执行完,A组件就已经被卸载,接着就渲染了B组件.
提示中提到的 Can’t perform a React state update on an unmounted component. 就是因为A组件已经被卸载了,导致异步函数中的渲染已经无效了

解决方案

第一种,不加载A组件,
第二种,等A组件渲染完之后再渲染B组件

猜你喜欢

转载自blog.csdn.net/weixin_43614065/article/details/124313629