Today I Learned

hashrocket A Hashrocket project

PropTypes Array of Shape

Today I defined PropTypes in a way I hadn't before: an array of objects with a defined shape.

Here's the data:

const items = [{ code: 'ZZ', id: 1 }, { code: 'YY', id: 2 }];

And the typechecking:

MyComponent.propTypes = {
  items: PropTypes.arrayOf(
      code: PropTypes.string,
      id: PropTypes.number,
See More #react TILs
Looking for help? At Hashrocket, our JavaScript experts launch scalable, performant apps on the Web, Android and iOS. Contact us and find out how we can help you.