呼唤孙子的功能作出反应

时间:2017-06-11 12:45:54

标签: reactjs react-native

我打算使用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
   })
 }
}

0 个答案:

没有答案