react 生命周期(舊)
1. 初始化階段: 由reactdom.render()觸發---初次渲染
1. constructor()
2. componentwillmount()
3. render()
4. componentdidmount() ====> 常用
一般在這個鈎子中做一些初始化的事,例如:開啟定時器、發送網絡請求、訂閱消息
2. 更新階段:由元件内部this.setstate()或父元件render觸發
1. shouldcomponentupdate()
2. componentwillupdate()
3. render() ====> 必須使用的一個
4. componentdidupdate()
3. 解除安裝元件:由reactdom.unmountcomponentatnode()觸發
1. componentwillunmount() ====> 常用
一般在這個鈎子中做一些收尾的事,例如:關閉定時器、取消訂閱消息
點選+1按鈕
點選解除安裝按鈕
強制更新:forceupdate()
不管更新的 "閥門" 有沒有開啟,強制更新都是會執行 render 的,但是如果閥門關閉,正常更新是不會執行 render 的
componentwillreceiveprops 父元件第二次及以後render,子元件會執行