React16新增生命周期與舊版本生命周期的區別


舊版本生命周期:

React16新增生命周期:

總結:

1.React16新的生命周期棄用了componentWillMount、componentWillReceivePorps,componentWillUpdate

2.新增了getDerivedStateFromProps、getSnapshotBeforeUpdate來代替棄用的三個鈎子函數(componentWillMount、componentWillReceivePorps,componentWillUpdate)

3.React16並沒有刪除這三個鈎子函數,但是不能和新增的兩個鈎子函數(getDerivedStateFromProps、getSnapshotBeforeUpdate)混用。注意:React17將會刪除componentWillMount、componentWillReceivePorps,componentWillUpdate

4.新增了對錯誤處理的鈎子函數(componentDidCatch)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM