react es6 怎么設置默認的props 于 state
1 回答

函數式編程
TA貢獻1807條經驗 獲得超9個贊
state在constructor方法里寫
...
constructor(props) {
this.state = {
n: ...
}
}
寫default props有兩種方法
//1 在組件內部的使用static
...
static defaultProps = {
name: ...
}
//2 在組件外部
Hello.defaultProps = {
name: ...
}
- 1 回答
- 0 關注
- 1164 瀏覽
添加回答
舉報
0/150
提交
取消