Component A
this.state = {
x: 1,
y: 2
}
reset () {
this.setState ({
x: 3,
y: 5
})
}
render () {
<B x = {this.state.x} y = {this.state.y} onClick = {this.reset.bind(this)}/>
}
================================================== ======
Component B
this.state = {
z: someMethod()
}
someMethod () {
return this.props.x + this.props.y
}
在 Click 上,我正在调用 reset 方法并更新组件 A 的状态,但如何重新呈现组件 B。现在它不更新组件 B。
Tried with
componentWillReceiveProps (nextProps) {
this.constructor(nextProps)
}