I create my component in the parent component this way:
renderRow(row){
var Buttons = new Array(this.props.w)
for (var i = 0; i < this.props.w; i++) {
var thisButton=<FieldButton handler={this.actionFunction} key={'row'+ row +'col'+ i}></FieldButton>
Buttons.push(thisButton)
}
return Buttons
}
renderField(){
var Field = new Array(this.props.h);
for (var i = 0; i < this.props.h; i++) {
var row = this.renderRow(i);
Field.push(<View key={i} style={styles.fieldWrap}>{row}</View>);
}
this.setState({field: Field})
}
The Goal:
I have to change the state of the FieldButton component.
My question:
What is the right way to change the Childs component state?
First Attempt:
I tried to bind a prop to the state of the parent component:
<FieldButton color={this.state.color} handler={this.actionFunction} key={'row'+ row +'col'+ i}></FieldButton>
I also implemented the componentWillReceiveProps Method but it was never called.
I tried to move the child outside of the for loop and it worked.
Second Attempt:
I tried to use refs: this question.