//Parent.js
class Parent extends React.Component {
constructor() {
super();
this.state = {
name: "zhangsan"
}
}
test() {
this.setState({
name: "lisi"
})
}
render() {
return (
<div>
<button onClick={this.test.bind(this)}>gogo</button>
<Sub1 />
</div>
)
}
}
export default Parent
//Sub1.js
class Sub1 extends React.Component {
componentWillReceiveProps(nextProps) {
console.log("componentWillReceiveProps from sub1")
}
render() {
return <div>Sub1x</div>
}
}
export default Sub1
props is not set when loading Sub1 in Parent.
is it reasonable that the state in Parent changes when the button is clicked, causing the componentWillReceiveProps event to be triggered in Sub1?