admin管理员组文章数量:1201411
I have the following TextInput Component:
<TextInput value={this.state.inputText}
maxLength={1}
onSubmitEditing={this.textHandler}
onChangeText={(text) => this.setState({inputText: text})} />
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'"
I tried deleting each callback and apparently, the error is throwed because of the 'onSubmitEditing'.
textHandler = (text) => {
if(text == '' || text == '-' ){
text = '0';
}
this.setState({inputText: text});
}
How can I make the callback to be called only where text is a string and not an object?
I have the following TextInput Component:
<TextInput value={this.state.inputText}
maxLength={1}
onSubmitEditing={this.textHandler}
onChangeText={(text) => this.setState({inputText: text})} />
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'"
I tried deleting each callback and apparently, the error is throwed because of the 'onSubmitEditing'.
textHandler = (text) => {
if(text == '' || text == '-' ){
text = '0';
}
this.setState({inputText: text});
}
How can I make the callback to be called only where text is a string and not an object?
Share Improve this question asked Jul 18, 2017 at 8:54 MichaelMichael 2412 gold badges3 silver badges9 bronze badges2 Answers
Reset to default 11change your onSubmitEditing
to
onSubmitEditing={(event) => this.textHandler( event.nativeEvent.text )}
Its a function, and you haven't passed value to it. If you want to pass you can get it from event
But you have used onChangeText
which will update inputText
so you just need to check value exists or not.
I have faced the same issue. It normally occurs Invalid or wrong props types of the components or elements.
My case I have put in <TextInput onChangeText={}/>
instead of <TextInput onChange={}/>
. So I have faced the problem. Please check your props type first right or wrong. It's working for me.
本文标签:
版权声明:本文标题:javascript - Failed prop type: Invalid prop 'value' of type 'object' supplied to 'TextIn 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738596000a2101789.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论