原文:React報錯: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,

今天在開發時報了以下錯誤,記錄一下 我們不能在組件銷毀后設置state,防止出現內存泄漏的情況 出現原因直接告訴你了,組件都被銷毀了,還設置個錘子的state啊 解決方案: 利用生命周期鈎子函數:componentWillUnmount 將報錯的地方移入此鈎子里進行處理 componentWillUnmount 處理邏輯 ...

2019-03-12 11:26 0 16265 推薦指數:

查看詳情

解決react報錯:index.js:1 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

報錯信息如下: 首先,這個報錯的意思是說:在路由快速切換時,數據還沒有拿回來,頁面就已經銷毀了,而當數據拿回來了去執行this.setState()時,找不到組件而報錯。 清楚問題后,解決的辦法有兩個: 第一種:在生命周期UNSAFE_componentWillMount里面取消 ...

Sun Apr 26 19:18:00 CST 2020 0 2267
index.js:1 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

React開發中,我們可能經常會遇到這個一個警告: 我們不能在組件銷毀后設置state,防止出現內存泄漏的情況: 關於react中切換路由時報以上錯誤,實際的原因是因為在組件掛載(mounted)之后進行了異步操作,比如ajax請求或者設置了定時器等,而你在callback ...

Fri Jul 10 03:43:00 CST 2020 1 806
關於Warning: setState(...): Can only update a mounted or mounting component. This usually means you called setState() on an unmounted component.

關於react中切換路由時報以上錯誤,實際的原因是因為在組件掛載(mounted)之后進行了異步操作,比如ajax請求或者設置了定時器等,而你在callback中進行了setState操作。當你切換路由時,組件已經被卸載(unmounted)了,此時異步操作中callback還在執行 ...

Thu Dec 07 20:59:00 CST 2017 0 12727
 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM