Tag Archives: PropTypes

React: PropTypes: Shape within Shape causes unwanted ‘isRequired’ – looks like a bug?

PropTypes are used for setting stricter types in React than JavaScript has traditionally supported (similar to TypeScript for Babel).

One of the types is shape , which allows you to describe the properties of an object, and their proptypes too.

However, if I declare a proptype as a shape within a shape, thus:

I get an error:

As can be seen above, the .isRequired  property has not been set at all!

Solution (Workaround)

If the inner shape is defined PRIOR to referencing it within the propTypes shape, the PropTypes library doesn’t throw the error: