2024-01-13 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. ==》引用了未使用的方法导致

发布时间 2024-01-13 09:44:38作者: 哎呦你可棒棒了

react+antd业务代码报错:

 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状态更新。这是一个非操作,但它表明应用程序中存在内存泄漏。若要修复此问题,请取消useEffect清理函数中的所有订阅和异步任务。

原因:代码中引用了antd的一些组件,并导出了里面的一个方法,而该方法并没有被使用导致报错。

解决方案:去除引用了却不会使用的方法或变量,确保每一行代码可用,都有其存在的理由。