React?Native組件的生命周期比較簡單,主要常用的主要用
1. constructor(props){}
2. render() {return (...)}
3.?componentWillUnmount(){}
4.?在用子組件情況,會先進行父組件的componentWillMount --> 子組件的初始化 -->?父組件render -->?父組件 componentDidMount
其生命周期主要分為三塊,
1、組件初始化mount裝載,只調用一次,可在constructor處進行state的初始化
2、組件更新update,?調用多次,每當props或者state發生改變時會調用,平時開發可在shouldComponentUpdate處寫邏輯判斷進行必要的性能優化。
3、卸載unmount,?可在此處進行其他事件等的銷毀
代碼演示生命周期過程:
1.初始化mount
2.?更新update
3. unmount