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, cancel all subscriptions and asynchronous tasks in the componentWillUnmount method.
原因:
通常是 react 組件已經(jīng)從 DOM 中移除(有時候是熱更新引起的)辩棒,但是我們在組件中做的一些異步操作還未結(jié)束邦尊,如:接口調(diào)用或者是一個setState的異步操作等,當(dāng)其完成時炕倘,而此時我們已經(jīng)將改組件dom移除罕邀,從而導(dǎo)致上述問題玄呛。
解決辦法:
componentWillUnmount() {
this.setState = (state, callback) => {
return
}
}