React內存泄漏問題結局方案

Warning: Can't perform a React state update on 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 componenWillUnmount method.

導致原因:

    很明顯這種情況就是在 dom 結構銷燬的時候,事件卻沒有清除導致的內存泄漏,所以我們需要在componentWillUnmount的時候去清除掛載的

  這裏就提到了內存泄露,當我們在使用事件綁定,setInterval,setTimeOut 或一些函數的時候,但是卻沒有在組件銷燬前清除的時候會造成內存泄露。這裏我們手動的再componentWillUnmount去清除相關的方法即可。

解決方案:

    componentwillUnmount(){

        this.setState=()=>{

             return;

       }

  }

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章