是否可以使用Rect.PropTypes來強制數組的長度?具有特定長度的React.PropTypes數組
這是一個非常簡單的例子:剛對象,因此我想這
const TWO_NUMBERS = PropTypes.array; // i need this to be an array of two numbers
我知道在JavaScript的數組是:
const TWO_NUMBERS = PropTypes.shape({
0: PropTypes.number.isRequired,
1: PropTypes.number.isRequired,
});
然而,這一直告訴警告我expected an object but got an array
。
非常感謝你finalfreq!我是新來的proptypes,我絕對喜歡這個! – Noitidart