【发布时间】:2019-12-15 11:33:16
【问题描述】:
我应该如何在每次道具更改时重置 Child 的状态?
父组件:
render() {
const { show, month } = this.props; // January, February, ...
return (
{ show ? <Child selectedMonth={month} /> : null }
);
}
子组件:
componentDidMount() {
this.resetChildState();
// this will never run if the Parent's month prop is changed
// only if show becomes false from true
}
我希望 resetChildState 在每个月更改时运行。
【问题讨论】:
-
使用
setState ("")
标签: reactjs