react getinitialstate怎么不調(diào)用
1 回答

aluckdog
TA貢獻(xiàn)1847條經(jīng)驗(yàn) 獲得超7個(gè)贊
1、React在ES6的實(shí)現(xiàn)中去掉了getInitialState這個(gè)hook函數(shù),規(guī)定state在constructor中實(shí)現(xiàn),如下:ClassAppextendsReact.Component{constructor(props){super(props);this.state={};}}2、Babel的Blog上還有一種實(shí)現(xiàn)方法,即直接使用賦值語句:ClassAppextendsReact.Component{constructor(props){super(props);}state={}}
- 1 回答
- 0 關(guān)注
- 673 瀏覽
添加回答
舉報(bào)
0/150
提交
取消