[React] Cant perform a React state update on an unmounted component 是props傳值數據修改了引出的bug

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. 

起因: 

 

 

 

解決辦法:

splice改slice, splice會改變源數據

 

原因:

react props是單向數據傳輸的, 但是項目用了splice修改了props的源數組數據, 導致控制檯打印源數組數據展開是[]的現象; 

react 規定props是單向數據流, 但是沒想到還能被修改到, 因此引出各種莫名其妙的bug, 謹以此發貼記錄. 

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