React中內部組件生命週期的運行方式。html
類調用:
此過程僅在類建立時被一次,即不管建立多少個ReactElement,此過程均只會執行一次函數
getDefaultProps測試
實例化:
此過程僅執行一次,執行完畢後,React組件真正被渲染到DOM中
期間執行生命週期函數以下:this
getInitialStatespa
componentWillMountcode
rendercomponent
componentDidMounthtm
變動 blog
此過程會在this.state
或this.props
變動時執行
期間執行生命週期函數以下:生命週期
this.state
變動
shouldComponentUpdate
componentWillUpdate
render
componentDidUpdate
this.props
變動
componentWillReceiveProps
shouldComponentUpdate
componentWillUpdate
render
componentDidUpdate
卸載
此過程在組件銷燬前調用一次期間執行生命週期函數以下:
componentWillUnmount
整個生命週期所涉及的方法如圖所示:
<Super> <Sub_1 /> <Sub_2 /> </Super>