生命周期
Screen Shot 2017-08-20 at 4.32.56 PM.png
終于找到這張圖(出處《Mastering React Native》),特地測(cè)試了下,僅當(dāng)state發(fā)生改變時(shí)市咆,
componentWillReceiveProps
是不會(huì)被調(diào)用的犁享,僅在props改變時(shí)調(diào)用。
- componentWillMount奔穿、componentDidMount
僅在初次渲染前后被調(diào)用一次镜沽,之后不會(huì)用到,無參數(shù) - componentWillReceiveProps(nextProps): 接受一個(gè)參數(shù)贱田,每當(dāng)props屬性改變時(shí)被調(diào)用
- componentShouldUpdate(nextProps, nextState): 默認(rèn)返回 true, 即每當(dāng)props或state改變時(shí)都渲染
- componentWillUpdate(nextProps, nextState): render方法被調(diào)用前的最后一個(gè)方法
- render: 渲染
- componentDidUpdate(prevProps, prevState): 渲染后調(diào)用缅茉,參數(shù)為之前的props和state
- componentWillUnmount(): 組件銷毀前方法,一般用來清理定時(shí)器等