constructor(props, context)
構造函數在創建組件的時候被調用;
void componentWillMount()
在掛載之前被調用,如果在這個函數裏面調用setState,本次的render函數可以看到更新後的state,並且只渲染一次。
void componentDidMount()
在掛載之後被調用
void componentWillReceiveProps(nextProps)
props是父組件傳遞給子組件的。父組件發生render的時候子組件就會調用componentWillReceiveProps(不管props有沒有更新,也不管父子組件之間有沒有數據交換)。
bool shouldComponentUpdate(nextProps, nextState)
組件掛載之後,每次調用setState後都會調用shouldComponentUpdate判斷是否需要重新渲染組件。
void componentWillUpdate(nextProps, nextState)
shouldComponentUpdate返回true或者調用forceUpdate之後,componentWillUpdate會被調用。
void componentDidUpdate()
除了首次render之後調用componentDidMount,其它render結束之後都是調用componentDidUpdate。
componentWillMount、componentDidMount和componentWillUpdate、componentDidUpdate可以對應起來。區別在於,前者只有在掛載的時候會被調用;而後者在以後的每次更新渲染之後都會被調用。
void componentWillUnmount()
組件被卸載的時候調用。一般在componentDidMount裏面註冊的事件需要在這裏刪除。