組件的分成三個(gè)狀態(tài):
- Mounting:已插入真實(shí) DOM
- Updating:正在被重新渲染
- Unmounting:已移出真實(shí) DOM
React 為每個(gè)狀態(tài)都提供了兩種處理函數(shù),will 函數(shù)在進(jìn)入狀態(tài)之前調(diào)用,did 函數(shù)在進(jìn)入狀態(tài)之后調(diào)用秕脓,三種狀態(tài)共計(jì)五種處理函數(shù)透乾。
- componentWillMount()
- componentDidMount()
- componentWillUpdate(object nextProps, object nextState)
- componentDidUpdate(object prevProps, object prevState)
- componentWillUnmount()
此外会油,React 還提供兩種特殊狀態(tài)的處理函數(shù)虚缎。
- componentWillReceiveProps(object nextProps):已加載組件收到新的參數(shù)時(shí)調(diào)用
- shouldComponentUpdate(object nextProps, object nextState):組件判斷是否重新渲染時(shí)調(diào)用