英文:
Failed prop type: Invalid prop 'value' of type 'object' supplied to 'TextInput'
问题
当我将输入更改为''并提交它(在TextInput中),我会遇到以下错误:"属性类型不匹配:无效的属性'value',类型为'对象',提供给'TextInput'"。
<TextInput
style={styles.input}
autoCapitalize='none'
onChange={email => this.setState({email})}
value={this.state.email}
>
英文:
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
style={styles.input}
autoCapitalize='none'
onChange={email => this.setState({email})}
value={this.state.email}
>
答案1
得分: 1
你的 onChange()
方法应该如下所示:
<TextInput
style={styles.input}
autoCapitalize='none'
onChange={(e) => {
this.setState({
email: e.nativeEvent.text
})
}}
value={this.state.email}
>
或者你可以使用 onChangeText()
将输入的文本分配给你的状态,如下所示:
<TextInput
style={styles.input}
autoCapitalize='none'
onChangeText={(email) => this.setState({ email })}
value={this.state.email}
>
更多文档在此。
英文:
Your onChange()
method should be as follow:
<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 :
<TextInput
style={styles.input}
autoCapitalize='none'
onChangeText={(email) => this.setState({ email })}
value={this.state.email}
>
More doc here.
答案2
得分: 0
如果您已经像这样定义了您的状态:
state={email:''} // 或者
this.state={email:''}
更改的代码如下:
<TextInput
style={styles.input}
autoCapitalize='none'
onChange={e => this.setState({email: e.target.value})}
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}
>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论