react native get TextInput value

前端 未结 16 2022
一生所求
一生所求 2020-12-04 16:10

I am stuck with a very simple problem. I have login form with username, password and button. In my button handler, I try to get the textinput value. But always get undefined

16条回答
  •  情深已故
    2020-12-04 16:40

    Please take care on how to use setState(). The correct form is

    this.setState({
          Key: Value,
        });
    

    And so I would do it as follows:

    onChangeText={(event) => this.setState({username:event.nativeEvent.text})}
    ...    
    var username=this.state.username;
    

提交回复
热议问题