寫(xiě)react的時(shí)候就想做一種你總是能找到簡(jiǎn)便方法的數(shù)學(xué)題一樣,做的時(shí)候停不下來(lái)冯袍。
start
getDefaultProps
1 .推薦寫(xiě)法
class TodoList extends Component{
constructor(){
super(props)
this.state({
})
}
}
TodoList.defaultProps={
name:'libateer'
}
getInitialState
1 .推薦寫(xiě)法
componentWillMount
render
componentDidMount
1 .可以在這個(gè)后面使用ref屬性犬钢,雖然可以抓到具體的元素苍鲜,但是對(duì)于異步獲取的資源必須要等到加載下來(lái)之后才可以獲取到
2 .做一些初始化的操作
componentWillUnmount
1 .卸載函數(shù),一些定時(shí)器
數(shù)據(jù)更新所遇到的函數(shù)
componentWillReceiveProps
1 .已加載組件接收到新的參數(shù)
shouldComponentUpdate
1 .組件判斷是否重新渲染時(shí)調(diào)用
2 .nextProps,nextState