在React组件中,我声明了以下内容:
static propTypes = {
data: PropTypes.shape({
id: PropTypes.string.isRequired,
title: PropTypes.string.isRequired,
handle: PropTypes.string.isRequired,
tags: PropTypes.array.isRequired,
images: PropTypes.shape({
edges: PropTypes.object({
node: PropTypes.shape({
src: PropTypes.string
})
})
}).isRequired
}),
images: PropTypes.object.isRequired,
onClick: PropTypes.func
}
在到达images
时,构建似乎适用于所有情况,此时它说Calling PropTypes validators directly is not supported by the prop-types package. Use PropTypes.checkPropTypes() to call them.
我不理解使用静态对象作为参数与为什么引发此错误之间的关系。这也不是我的代码,所以我不太确定为什么图像道具无法展平。
答案 0 :(得分:1)
您不能直接以形状调用PropTypes.object()。试试这个
images: PropTypes.shape({
edges: PropTypes.shape({
node: PropTypes.shape({
src: PropTypes.string
})
})
}).isRequired