React Warning: Failed prop type: Invalid prop of type `Object` supplied

Kaboukie picture Kaboukie · Oct 18, 2018 · Viewed 8.2k times · Source

I am getting the warning "Warning: Failed prop type: Invalid prop of type Object supplied to , expected instance of bound checkType."

This is my 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? 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. 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.

Answer

Gatsbimantico picture Gatsbimantico · Oct 19, 2018

For object when react/forbid-prop-types eslint is enabled, try to use shapes:

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