子组件正在从其父组件接收许多更新的道具。如果道具中有任何更新,我想更新子组件。目前,我正在使用componentWillReceiveProps
按预期工作的生命周期方法进行更新。
componentWillReceiveProps(nextProps){
if(this.props.scale_length !== nextProps.scale_length){
const {scale_height,scale_breadth} = this.props
this.setState({
torsoScale: new
THREE.Vector3(nextProps.scale_length,scale_height,scale_breadth)
});
}
if(this.props.scale_breadth !== nextProps.scale_breadth){
const {scale_height,scale_length} = this.props
this.setState({
torsoScale: new
THREE.Vector3(scale_length,scale_height,nextProps.scale_breadth)
});
}
...
}
但是,我将来会得到 8 个以上的道具。我将如何继续。谢谢。