简体   繁体   English

警告:道具类型失败:提供给“ForwardRef(FormControl)”的“string”类型的道具“error”无效,预期为“boolean”

[英]Warning: Failed prop type: Invalid prop `error` of type `string` supplied to `ForwardRef(FormControl)`, expected `boolean`

I have a material-ui Textfield component in my ReactJS project.我的 ReactJS 项目中有一个 material-ui 文本字段组件。

When I run my code, the warning I got in the console is:当我运行我的代码时,我在控制台中收到的警告是:

Warning: Failed prop type: Invalid prop `error` of type `string` supplied to `ForwardRef(FormControl)`, expected `boolean`.

My component code is below.我的组件代码如下。 <Field label="First Name*" name="firstName" component={InputField} type="text" placeholder="First Name" className="form-control" /> This code works totally fine but the problem is that it gives a warning message in the console. <Field label="First Name*" name="firstName" component={InputField} type="text" placeholder="First Name" className="form-control" />这段代码工作得很好,但问题是它在控制台中给出警告消息。

Warning: Failed prop type: Invalid prop error of type string supplied to ForwardRef(TextField) , expected boolean .警告:道具类型失败:提供给ForwardRef(TextField)string类型无效道具error ,预期boolean

Is there any ES6 or any other solution to this?是否有任何 ES6 或任何其他解决方案?

This warning comes when you are passing a string value to the boolean property in mui.当您将字符串值传递给 mui 中的 boolean 属性时会出现此警告。 Like "error", when you give it true it will show an error else will be normal.就像“错误”一样,当您将其设置为真时,它将显示错误,否则将是正常的。 And if you doing like this error={"some state"} give this a default boolean value otherwise this warning will be displayed.如果你这样做 error={"some state"} 给它一个默认值 boolean 否则会显示这个警告。

I had a similar error, I solved changing the default value for a non-empty string我有一个类似的错误,我解决了更改非空字符串的默认值

you can set the value to null if the not found or undefined如果not foundundefined ,您可以将值设置为 null

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 警告:道具类型失败:提供给 `ForwardRef(Slider)` 的道具 `value` 无效 - Warning: Failed prop type: Invalid prop `value` supplied to `ForwardRef(Slider)` reactjs 失败的道具类型:提供给“ForwardRef(IconButton)”的“object”类型的无效道具“className”,应为“string” - reactjs Failed prop type: Invalid prop `className` of type `object` supplied to `ForwardRef(IconButton)`, expected `string` 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` 警告:道具类型失败:类型为“字符串”的无效道具“错误”预期为“布尔值” - Warning: Failed prop type: Invalid prop `error` of type `string` expected `boolean` Mui5 TextField 提供给“ForwardRef(InputBase)”的“boolean”类型的无效道具“autoComplete”,应为“字符串” - Mui5 TextField Invalid prop `autoComplete` of type `boolean` supplied to `ForwardRef(InputBase)`, expected `string` 道具类型失败:提供给“ForwardRef(DataGrid)”的“object”类型的无效道具“rows”,预期为“array” - Failed prop type: Invalid prop `rows` of type `object` supplied to `ForwardRef(DataGrid)`, expected `array` 警告:失败的道具类型:提供给`Dropzone`的类型`string`的prop`child`无效,期望的`function` - Warning: Failed prop type: Invalid prop `children` of type `string` supplied to `Dropzone`, expected `function` 失败的道具类型:提供给“ForwardRef(Grid)”的无效道具“lg” - Failed prop type: Invalid prop `lg` supplied to `ForwardRef(Grid)` 获取错误:警告:道具类型失败:提供给“Form”的道具“children”无效,应为 ReactNode - GETTING ERROR : Warning: Failed prop type: Invalid prop `children` supplied to `Form`, expected a ReactNode React Native +图标:警告:失败的道具类型:无效的props.style键tintColor提供给ForwardRef(Text) - React Native + Icons: Warning: Failed prop type: Invalid props.style key tintColor supplied to ForwardRef(Text)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM