Component A
this.state = {
x: 1,
y: 2
}
reset () {
this.setState ({
x: 3,
y: 5
})
}
render () {
You need to setState
for the second component too in the componentWillReceiveProps
function. Constructor is only called on intial render and state should not be only assigned in the contructor if it depends on props
componentWillReceiveProps (nextProps) {
this.setState({z: nextProps.x + nextProps.y})
}
if you want to use someMethod do it like
someMethod(props) {
props? return props.x + props.y : return this.props.x + this.props.y
}
and then in componentWillReceiveProps
componentWillReceiveProps (nextProps) {
var z = someMethod(nextProps)
this.setState({z})
}