React proptype array with shape

前端 未结 6 1084
感情败类
感情败类 2020-12-12 15:11

Is there a built-in way to use proptypes to ensure that an array of objects being passed to a component is actually an array of objects of a specific shape?

Maybe so

6条回答
  •  囚心锁ツ
    2020-12-12 15:49

    And there it is... right under my nose:

    From the react docs themselves: https://facebook.github.io/react/docs/reusable-components.html

    // An array of a certain type
        optionalArrayOf: React.PropTypes.arrayOf(React.PropTypes.number),
    

提交回复
热议问题