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