简体   繁体   English

反应警告:失败的道具类型:提供的“对象”类型的无效道具

[英]React Warning: Failed prop type: Invalid prop of type `Object` supplied

I am getting the warning "Warning: Failed prop type: Invalid prop of type Object supplied to , expected instance of bound checkType ." 我收到警告“警告:失败的道具类型:提供的类型为Object无效道具,预期的bound checkType实例。”

This is my proptypes: 这是我的proptypes:

FieldTable.propTypes = {
    rawData: PropTypes.instanceOf(PropTypes.object).isRequired,
    percentCols: PropTypes.arrayOf(PropTypes.string).isRequired,
    specialColNames: PropTypes.instanceOf(PropTypes.object).isRequired,
    scenarioHeaders: PropTypes.instanceOf(PropTypes.object),
    headerHierarchies: PropTypes.arrayOf(PropTypes.object).isRequired
};

What is this 'bound checkType' it is referring to and how should I be validating my object props to avoid this warning? 它指的是什么是'bound checkType',我应该如何验证我的对象道具以避免这个警告? The objects themselves are JSON objects received from asynchronous calls, and generated in other components.The rawData object, for example, comes from a component that lets the user upload an excel spreadsheet then parses the spreadsheet into a JSON object. 对象本身是从异步调用接收的JSON对象,并在其他组件中生成。例如,rawData对象来自一个组件,该组件允许用户上载excel电子表格,然后将电子表格解析为JSON对象。 Don't know if that's useful information or not. 不知道这是否有用。

Thanks for any assistance and especially any deeper discussions that may arise from this question. 感谢您提供任何帮助,特别是此问题可能产生的任何更深入的讨论。

对于启用react/forbid-prop-types eslint的对象,请尝试使用形状:

plainObj: PropTypes.shape({ subProp: PropTypes.string })

要检查普通JS对象的proptypes,你应该只使用:

plainObj: PropTypes.object.isRequired,

暂无
暂无

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

相关问题 警告:道具类型失败:提供给“路由”的道具“组件”无效:道具不是路由中的有效 React 组件 - Warning: Failed prop type: Invalid prop 'component' supplied to 'Route': the prop is not a valid React component in Route 警告:失败的道具类型:提供给“路由”的“对象”类型的无效道具“组件”,预期的“函数”使用 react-router-dom 错误 - Warning: Failed prop type: Invalid prop `component` of type `object` supplied to `Route`, expected `function` Error using react-router-dom 警告:失败的道具类型:提供给“图像”的无效道具'源' - Warning: Failed prop type: Invalid prop 'source' supplied to 'Image' 警告:道具类型失败:提供给“路线”的道具属性无效。 在途中 - Warning: Failed prop type: Invalid prop `component` supplied to `Route`. in Route 警告:道具类型失败:提供给“ DropdownItem”的道具“ as”无效 - Warning: Failed prop type: Invalid prop `as` supplied to `DropdownItem` 警告:道具类型失败:提供给 `ForwardRef(Slider)` 的道具 `value` 无效 - Warning: Failed prop type: Invalid prop `value` supplied to `ForwardRef(Slider)` 警告:道具类型失败:提供给“Form(AddComment)”的道具“initialValues”无效 - Warning: Failed prop type: Invalid prop `initialValues` supplied to `Form(AddComment)` 警告:道具类型失败:提供给“NavLink”的道具“标签”无效 - Warning: Failed prop type: Invalid prop `tag` supplied to `NavLink` 失败的道具类型:提供给“RCTView”的“对象”类型的无效道具“不透明度” - Failed prop type: Invalid prop `opacity` of type `object` supplied to `RCTView` 失败的道具类型:提供给“TextInput”的“对象”类型的道具“值”无效 - Failed prop type: Invalid prop 'value' of type 'object' supplied to 'TextInput'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM