Is there a better way to validate if a number is inside a range?
Avoiding to write
PropTypes.oneOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
You can use custom Prop validator.
completed: function(props, propName, componentName) {
if (props[propName]>=1 && props[propName]<=10) {
return new Error(
'Invalid prop `' + propName + '` supplied to' +
' `' + componentName + '`. Validation failed.'
);
}
}
Please refer the documentation for further details.
https://reactjs.org/docs/typechecking-with-proptypes.html