I have a component that gets a badge prop (see example below). The icon is optional, but as soon as it is used, I want it to have some required fields. I tried the following:
Component.propTypes = { badge: PropTypes.shape({ src: PropTypes.string.isRequired, alt: PropTypes.string.isRequired, }), }
This works, but I get this warning in Chrome when I try to use it without an icon:
Warning: Faulty support type: The proportion of badge.src marked as required in Component , but its value is null .
What is the right way to do this?
Component usage example:
badge={{ src: 'usa.png', alt: 'United States' }}
badge not supplied
source share