最新版React( V16.3)生命週期、性能優化及注意事項

學習React免不了對組件生命週期的學習,咱們應該掌握最新生命週期,學以至用,以達到性能優化的目的。html


The Component Lifecycle

React Version: 16.3react

1 生命週期可視化

瞭解最新版的React生命週期,知道其特性(如:異步渲染),有助於開發高性能React程序。性能優化

高清大圖異步

React最新生命週期:The Component Lifecycle Flowchart

2 簡要總結:

  • 去掉了3個方法
  1. componentWillMount
  2. componentWillReceiveProps
  3. componentWillUpdate
  • 增長了2個方法
  1. static getDerivedStateFromProps(nextProps, prevState)
  2. getSnapshotBeforeUpdate(prevProps, prevState)
  • 更改了1個方法,增長了第3個參數
  1. componentDidUpdate(prevProps, prevState, snapshot)
  • 更改緣由: 官網說是爲了實現未來新版本的異步渲染In order to support async rendering

最後

但願感興趣的小夥伴兒能夠觀看官網,深刻了解和學習。async

官網文檔: https://reactjs.org/docs/react-component.html#static-getderivedstatefromprops性能

相關文章
相關標籤/搜索