ReactJS 新的 PropType 包抛出错误

ReactJS new PropType package Throws Error

在 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.

我不明白使用静态对象作为参数与抛出此错误的原因之间的关系。这也不是我的代码,所以我不完全确定为什么 images 道具不能被展平。

您不能直接在形状中调用 PropTypes.object()。试试这个

images: PropTypes.shape({
     edges: PropTypes.shape({
        node: PropTypes.shape({
           src: PropTypes.string
        })
     })
}).isRequired