我打算使用refs来调用曾孙的功能,但是不能确切地知道如何。请帮忙。请不要担心语法错误。下面是代码:
Main.js
render(){
<Board puzzle={puzzle} ref={ref => this.board = ref} solve={this.solve} editing={editing}
onInit={this.onInit.bind(this)} onErrorMove={this.onErrorMove} onFinish={this.onFinish} erasing={this.state.erasing}/>
}
Board.js
render(){
<Grid ref={ref => ref && (this.cells = ref.cells)} onPress={this.onCellPress} number={index} erasing={this.props.erasing}/>
}
Grid.js
render(){
<Cell ref={ref => this.cells[index] = ref} key={'cell' + index} />
}
Cell.js;从Main.js
调用的函数erase(){
if(this.state.hints.length > 0){
this.setState({
hints: []
})
}
else {
this.setState({
number: null
})
}
}