【发布时间】:2018-04-01 23:46:32
【问题描述】:
我的 React 应用程序需要使用动态键来跟踪配置对象,所以我将它传递给这样的组件:
<Component configuration={this.state.configuration}>
虽然这有效,但当我在组件的componentWillReceiveProps(nextProps) 中时,我无法辨别配置更改,因为this.props 已经更新为nextProps。
如果这不是一个已知问题,也许它与我处理父级配置状态更新的方式有关?以下是我更新配置状态的方法:
handleConfigurationChangeForKey(newOption, key) {
const configObject = this.state.configuration;
configObject[key] = newOption;
this.setState({configuration: configObject});
}
提前感谢您的帮助。
【问题讨论】: