react子組件怎么改變父組件的state
4 回答

四季花海
TA貢獻(xiàn)1811條經(jīng)驗(yàn) 獲得超5個贊
你去好好看一下React組件生命周期這一部分。你可以在子組件添加一個componentWillRecieveProps周期,在里面獲取到即將接收的props。如下:
componentWillReceiveProps(nextProps) {
this.setState({
A: nextProps.A
});
}
- 4 回答
- 0 關(guān)注
- 694 瀏覽
添加回答
舉報(bào)
0/150
提交
取消