处理Text-INPUT REACT NATIVE

时间:2018-02-19 13:40:36

标签: react-native

如何将TextInput值传递给Translation.get(" Replace TextInput Value")

 handleKeyPress(e) {
  if(e.nativeEvent.key == ' '){
    console.log(e.nativeEvent.key);
      Translation.get(this.state.text).then(translated => {
      console.log(translated);
  });
  }
}

    <TextInput
        style={{height: 40, borderColor: 'gray', borderWidth: 1}}
        onKeyPress={this._handleKeyPress}
        onChangeText={(text) => this.setState({text})}
        value={this.state.text}
      />

注意:this.state.text对我不起作用

1 个答案:

答案 0 :(得分:0)

如果我理解你的问题,你只需设置新状态:

Translation.get(this.state.text).then(translated => {
      this.setState({ text: translated });
});