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(
PropTypes.shape({
code: PropTypes.string,
id: PropTypes.number,
})
),
};
Tweet