道具类型失败:数组类型为无效的道具,预期为对象

时间:2020-07-29 20:34:59

标签: reactjs react-proptypes

这是我的数据的样子: enter image description here

这是我的类型检查的样子:

SingleProduct.propTypes = {
  product: PropTypes.shape({
    title: PropTypes.string,
    description: PropTypes.string,
    images: PropTypes.arrayOf(
      PropTypes.shape({
        original: PropTypes.string,
      })
    ),
    specification: PropTypes.string,
    price: PropTypes.number
  }),
  
};

我收到此警告:

 Warning: Failed prop type: Invalid prop `product` of type `array` supplied to `SingleProduct`, expected `object`.

我的类型检查有什么问题?

1 个答案:

答案 0 :(得分:0)

我遇到了同样的错误。我删除了 .arrayOf() 并在我的嵌套值中声明了形状。所以在你的代码中试试这个:

images: PropTypes.shape({
        original: PropTypes.string,
      }),