获取 "The prop A is marked as required in B, but its value is 'undefined'." 即使未按要求设置

Getting "The prop A is marked as required in B, but its value is 'undefined'." even when it's not set as required

所以我以前都是根据需要设置一些道具。然后我改变了我的代码,得到了上面提到的错误。转到组件并删除了 .isRequired 并添加了默认道具...但我仍然收到错误消息???

我的项目仍然有点小,所以我很确定我没有以某种奇怪的方式复制组件。以为这可能是某种奇怪的缓存机制,但即使我 运行 处于隐身模式,问题仍然存在。我还重新启动了应用程序,以防在 WebPack 重新编译项目后 prop 类型以某种方式持续存在。

错误:

Warning: Failed prop type: The prop 'artist.isRequired' is marked as required in 'ArtistCard', but its value is 'undefined'.

Warning: Failed prop type: The prop 'trackMap.isRequired' is marked as required in 'ArtistCard', but its value is 'undefined'.

我的道具类型在 ArtistCard 中的外观:

ArtistCard.defaultProps = {
  artist: {},
  trackMap: {},
};

ArtistCard.propTypes = {
  artist: PropTypes.shape(PropTypes.object),
  trackMap: PropTypes.shape(PropTypes.object),
};

仔细检查我是否也保存了所有相关文件。这种行为的可能原因是什么?我可以在哪里调试它?

您应该使用 PropTypes.object 而不是 PropTypes.shape(PropTypes.object)

为了避免 linting 错误,我将 propTypes 改为:

ArtistCard.propTypes = {
  artist: PropTypes.shape({}),
  trackMap: PropTypes.shape({}),
};