關于對React生命周期的了解:
defaultProps:此為初始化props 用于頁面中資料傳入(2種寫法,一般元件内,大多情況不寫)
元件内
前端筆記 2020.4.2 (React生命周期) 元件外
前端筆記 2020.4.2 (React生命周期) constructor:狀态初始化
前端筆記 2020.4.2 (React生命周期) componentWillMount:元件渲染前執行
前端筆記 2020.4.2 (React生命周期) render:元件首次渲染
前端筆記 2020.4.2 (React生命周期) componentDidMount:元件首次渲染後回調
前端筆記 2020.4.2 (React生命周期) componentWillReceiveProps:元件的屬性被改變時的用法
用于父子元件互動,當父元件更改了子元件傳入的屬性時,子元件執行的生命周期
子元件:
前端筆記 2020.4.2 (React生命周期) 父元件:
給子元件傳個state作為更改,父元件上做個點選事件
前端筆記 2020.4.2 (React生命周期) 點選後變更state,render後執行到子元件
前端筆記 2020.4.2 (React生命周期) 子元件的componentWillReceiveProps就能取到新值
前端筆記 2020.4.2 (React生命周期) shouldComponentUpdate:setState後判斷是否要更新。一般用法,如果state沒有變化,就不更新了。
前端筆記 2020.4.2 (React生命周期) componentWillUpdate:确定更新,重新render前執行的
前端筆記 2020.4.2 (React生命周期) componentDidUpdate:已更新,重新render後執行的
前端筆記 2020.4.2 (React生命周期) 部落格園作者:herry菌,原文連結:
https://www.cnblogs.com/wuhairui/p/12622019.html
朋友,看到這裡,關注作者的公衆号吧,不漏掉更新哦
前端筆記 2020.4.2 (React生命周期)