When the roomThingId of the props changes, the getDerivedStateFromProps subcomponent gets the value againCopy the code
// This method returns equal to this.setState(), which is triggered frequently... static getDerivedStateFromProps(newProps, oldProps) {if(newProps.roomThingId ! == oldProps.roomThingId) {return {
...oldProps,
roomThingId: newProps.roomThingId,
}
}
return null;
}
componentDidUpdate(prevProps) {
if(this.state.roomThingId ! == this.props.roomThingId) { console.log('Change parameters, reset some parameters! prevProps:',prevProps)
console.log('Change parameters, reset some parameters! state:',this.state)
this.setState( {
roomThingId: this.props.roomThingId
})
}
}Copy the code