[英]Failed prop type: Invalid prop 'value' of type 'object' supplied to 'TextInput'
When I change the input to '' and submit it (in the TextInput) I have the following error: "Failed prop type: Invalid prop 'value' of type 'object' supplied to 'TextInput'"当我将输入更改为 '' 并提交它(在 TextInput 中)时,出现以下错误:“道具类型失败:提供给 'TextInput' 的类型为 'object' 的无效道具 'value'”
<TextInput
style={styles.input}
autoCapitalize='none'
onChange={email => this.setState({email})}
value={this.state.email}
>
Your onChange()
method should be as follow:您的onChange()
方法应如下所示:
<TextInput
style={styles.input}
autoCapitalize='none'
onChange={(e) => {
this.setState({
email: e.nativeEvent.text
})
}}
value={this.state.email}
>
Or you can just use onChangeText()
to assing entered text into your state as below :或者您可以使用onChangeText()
将输入的文本分配到您的状态,如下所示:
<TextInput
style={styles.input}
autoCapitalize='none'
onChangeText={(email) => this.setState({ email })}
value={this.state.email}
>
if you have defined your state like this如果你像这样定义了你的状态
state={email:''} // or
this.state={email:''}
changed code更改代码
<TextInput
style={styles.input}
autoCapitalize='none'
onChange={e=> this.setState({email:e.target.value})}
value={this.state.email}
>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.