react native get TextInput value

前端 未结 16 2037
一生所求
一生所求 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:42

    export default class App extends Component {
      state = { username: '', password: '' }
    
      onChangeText = (key, val) => {
        this.setState({ [key]: val})
      }
      
      render() { 
        return (
          
              Login Form
               this.onChangeText('username', val)}
                style={styles.input}
              />
               this.onChangeText('password', val)}
                style={styles.input}
                secureTextEntry={true}
              />      
          
        );
      }
    }

    Hope this will solve your problem

提交回复
热议问题