简体   繁体   English

失败的道具类型:提供给“TextInput”的“对象”类型的道具“值”无效

[英]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}
        >

Moredoc here.更多文档在这里。

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.

相关问题 道具类型失败:提供给“TextInput”React Native 的“对象”类型的无效道具“值” - Failed prop type: Invalid prop 'value' of type 'object' supplied to 'TextInput' React Native 警告:道具类型失败:提供给 `ForwardRef(Slider)` 的道具 `value` 无效 - Warning: Failed prop type: Invalid prop `value` supplied to `ForwardRef(Slider)` React Native SearchBar错误:道具类型失败:提供给`ForwardRef(TextInput)`的`array`类型的无效道具`value`,预期`string` - React Native SearchBar Error: Failed prop type: Invalid prop `value` of type `array` supplied to `ForwardRef(TextInput)`, expected `string` 失败的道具类型:向“表”提供了“功能”类型的道具“ rowSelection”无效,预期是“对象” - Failed prop type: Invalid prop `rowSelection` of type `function` supplied to `Table`, expected `object` reactjs 失败的道具类型:提供给“ForwardRef(IconButton)”的“object”类型的无效道具“className”,应为“string” - reactjs Failed prop type: Invalid prop `className` of type `object` supplied to `ForwardRef(IconButton)`, expected `string` 道具类型失败:提供给“ForwardRef(DataGrid)”的“object”类型的无效道具“rows”,预期为“array” - Failed prop type: Invalid prop `rows` of type `object` supplied to `ForwardRef(DataGrid)`, expected `array` 道具类型失败:提供给“按钮”的对象类型无效的道具“标签”,应为“字符串” - Failed prop type: Invalid prop `label` of type `object` supplied to `Button`, expected `string` 道具类型失败:提供给Styled(Container)的类型为number的道具类型无效,预期对象 - Failed prop type: Invalid prop `style` of type `number` supplied to `Styled(Container)`, expected `object` 道具类型失败:提供给“按钮”的“对象”类型的道具“ on​​Click”无效,预期是“功能” - Failed prop type: Invalid prop `onClick` of type `object` supplied to `Button`, expected `function` 警告:道具类型失败:提供给“提供者”的对象类型为“对象”的道具儿童无效,需要一个ReactElement - Warning: Failed prop type: Invalid prop `children` of type `object` supplied to `Provider`, expected a single ReactElement
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM