日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

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

作者:菜菜Caro 更新時間: 2021-12-16 編程語言

報錯如下:

在這里插入圖片描述

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 the componentWillUnmount method.

原因:

react組件已經被銷毀,無法對已卸載的組件執行React狀態更新。這是一個no-op,但它表示應用程序中存在內存泄漏。


解決方案:

在組件componentWillUnmount銷毀的時候將異步方法取消

componentWillUnmount() {
  this.setState = () => false;
}

原文鏈接:https://blog.csdn.net/Caroline_cai/article/details/122099290

欄目分類
最近更新