when a child component needs to modify the props passed by the parent component (think about this scenario),
can assign a value to its own state at initialization time
constructor (props) {
this.state = {
foo: props.foo
}
}
then operate state inside the component, but if you encounter the parent component updating props, then the constructor of the child component will no longer be called, so write
componentWillReceiveProps (nextProps) {
this.setState({ foo: nextProps.foo })
}
is it a bit troublesome to write like this, or I don"t understand the true meaning of it?