子コンポーネントを通って入ってくるデータに基づいて親コンポーネントの状態を変更しようとしています。私はボタンなしで親を変更する方法を理解できません。子要素のthis.state.rowsがデータベースから来て、データがロードされている間に回転アイコンを表示できるように状態を変更したいと思います。子コンポーネントの状態を、子コンポーネントのデータのレンダリングに基づいて変更しようとしています。
class Parent extends Component{
constructor(props){
super();
this.state={
spinner=false
}
this.spinnerUpdate = this.spinnerUpdate.bind(this)
}
spinnerUpdate(){}
render(){
return(
<Child spinner={this.spinnerUpdate}/>
)
}
}
class Child extends Component{
constructor(props){
super(props);
this.state={
rows: rows,
}
this.spinner = this.spinner.bind(this)
}
spinner(){
if(this.state.rows){
this.setState({spinner: true})
}
}
render(){
return(
<div>
//random info
</div>
)
}
}
私は、データがレンダリングされるとき、親状態の状態を変更するには、子コンポーネントでスピナー機能を期待しました。
このコードはコンパイルされません 'this.state =を{ スピナー=偽 }' –
spinnerUpdateはまた、私はこれを試みNOOP機能.... –