невозможно получить доступ к компоненту с ref - PullRequest
0 голосов
/ 29 апреля 2018

Почему this.workmin.value не определено?

captureInput=(text)=>{
    console.log('captureinput',this.refs.workmin.value)
  }

  render() {
    console.log('RENDER',this.state)


    return (
      <View style={styles.container}>
        <Text style={styles.bigFont}>{`${this.state.timer + 'TIMER'}`}</Text>
        <Text style={styles.bigFont}>{`${this.state.min + ':' + this.state.sec}`}</Text>
        <View style={styles.button}>
          <Button title='START' onPress={()=>this.startToggle()} />
          <Button title='RESET' onPress={()=>this.resetToggle()} />
        </View>
             <View style={styles.row}>
                <Text style={[styles.bold,{marginRight:10},{width:112},
                            {textAlign:'right'}]}>
                            Work Timer:</Text>
                <Text style={styles.bold}> min:</Text>
                <TextInput
                   
                   value={Math.floor(this.state.workTime / 60).toString()}
                   ref= {(ref)=>{this.workmin=ref}}
                   style={styles.input}
                   onChangeText={(text) => {this.captureInput(text)}}

                />
      </View>
    )
  }

1 Ответ

0 голосов
/ 29 апреля 2018

refs устарело, вместо этого сделайте следующее:

<TextInput
  ref={(ref) => {
    this.workmin = ref;
  }}
/>

Тогда вы можете использовать его как this.workmin.focus().

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...