constructor(props) {
super(props);
this.state = {
form:this.props.form
};
}
{this.props.form.name}
Why do I initialize the child component here to get the parent component data through pros
when my child component calls the parent component event to change the data
name can also be changed initialization method is not executed only once
when I have two components An and B A components call parent component method parent component data change
trigger B component data update operation, A component passes data as above
B component can not update data through componentWillReceiveProps () method
class ComModal extends React.Component{
constructor(props) {
super(props);
this.state = {
form:{
},
show:false
};
}
showChange(){
that.setState({
show:true
})
}
render(){
return(
<div>
<A cbclick={e=>that.showChange()}/>
<B show={that.state.show}/>
</div>
)
}
}
A
class A extends React.Component{
showChange()
}
B
class B extends React.Component{
constructor(props) {
super(props);
this.state = {
show:this.props.show //Ashow render
};
}
componentWillReceiveProps(nextProps){
}
render(){
return (
{that.state.show?"":""}
)
}
}