React.PropTypes.arrayOf( React.PropTypes.number ) just returns a function, so you can instead provide your own function to perform the validation.
Your function will be passed three parameters: props, propName, componentName
see the second to last example shown in React.PropTypes from the docs.
So a function that should satisfy your constraints would be:
function isTwoElementArrayOfNumbers( props, propName, componentName ){
var _array = props[ propName ];
if( _array && _array.constructor === Array && _array.length === 2 ){
if( !_array.every(
function isNumber( element ){
return typeof element === 'number';
})
){
return new Error('elements must be numbers!');
}
}
else{
return new Error('2 element array of numbers not provided!');
}
}
...in your react element
propTypes:{
numArray: isTwoElementArrayOfNumbers
},