我想为我的React组件之一指定PropTypes并且遇到了一些问题。我想描述的对象将看起来像这样(数组将包含多个对象):反应PropTypes - 形状与数字作为键
rounds: {
1: [
{
date: 1429354800000,
arena: 'Arena name',
scoreHome: 3,
scoreAway: 2,
teamHome: 'Home team name',
teamAway: 'Away team name',
spectators: 10
}
]
}
我不会事先知道有多少轮会有。所以,我可以结束了
rounds: { 1: [..], 2: [..], 3: [..] }
这是我现在有(不工作):
RoundsTable.propTypes = {
rounds: PropTypes.shape({
PropTypes.arrayOf(PropTypes.shape({
date: PropTypes.number.isRequired,
arena: PropTypes.string.isRequired,
scoreHome: PropTypes.number.isRequired,
scoreAway: PropTypes.number.isRequired,
teamHome: PropTypes.string.isRequired,
teamAway: PropTypes.string.isRequired,
spectators: PropTypes.number.isRequired
}).isRequired).isRequired
}).isRequired
}
我不知道如何来指定包含对象的数组数。这是我的一个数据设计问题还是有一个简单的解决方案来指定这些类型的道具?
是否有一个原因,你使用的是带有编号键的对象,而不是数组? –