Search code examples
reactjsreact-proptypes

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


So I used to have some props set as required. Then I changed my code, got the above mentioned error. Went to the component and removed the .isRequired and added default props... and I'm still getting the error???

My project is still kinda small, so I'm pretty sure I haven't duplicated the component in some weird way. Thought it could be some strange caching mechanism but the problem persists even when I run in incognito mode. I also restarted the application in case prop types somehow persisted after WebPack recompiles the project.

The error:

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

and

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

How my prop types look in ArtistCard:

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

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

Double checked that I saved all relevant files as well. What could possible reasons for this behaviour be? Where could I try to debug it?


Solution

  • You should use PropTypes.object instead of PropTypes.shape(PropTypes.object)