Reputation: 1
state={username:"",password:""}
...
<TextInput style={styles.inputStyle}
placeholder='[email protected]'
autoCorrect={false}
value={this.state.username}
onChange={text =>{
this.setState({username:text});
console.log(this.state.username);
}}
/>
The error I'm getting is value is being passed an object, and it cites the line this textInput begins, but I don't see how this is possible
Styles is just:
let styles ={
titleStyle:{
fontWeight:'bold',
fontSize: 20,
textAlign:'center'
},
inputStyle:{
backgroundColor:'#d4d4d4'
}
}
Inside the render.
Upvotes: 0
Views: 1025
Reputation: 106
Try to this code:
onChange={this.onUserChange}
onUserChange = (e, {value}) => {
if (value)
this.setState({username:value})
}
Upvotes: 0
Reputation: 1356
The onChange
will return you an object, if you use onChangeText
, it will return the value directly.
<TextInput
style={styles.inputStyle}
placeholder='[email protected]'
autoCorrect={false}
value={this.state.username}
onChangeText={text => this.setState({ username: text })}
/>
Or, if you want to use the onChange
you can do it in this way:
<TextInput
style={styles.inputStyle}
placeholder='[email protected]'
autoCorrect={false}
value={this.state.username}
onChange={event => this.setState({ username: event.target.value })}
/>
Read React Native - Difference between onChange vs onChangeText of TextInput
Upvotes: 2