Skip to main content
InterviewHubPRO
Section Overview
Q58

Question 58 of 407

General

14%
React Core & Hooks (407 Qs)•General

What is React proptype array with shape?

junior LevelCode ExampleData Structures

If you want to pass an array of objects to a component with a particular shape then use React.PropTypes.shape() as an argument to React.PropTypes.arrayOf().

javascript
import PropTypes from 'prop-types';

ReactComponent.propTypes = {
  arrayWithShape: PropTypes.arrayOf(
    PropTypes.shape({
      color: PropTypes.string.isRequired,
      fontSize: PropTypes.number.isRequired,
    })
  ).isRequired,
};