Answer the question
In order to leave comments, you need to log in
How to check data types of values passed to a function (prop-types)?
How to check data types of values passed to a function (prop-types) ?
There is a PropTypes.func type, but how do I check the types of the values passed to the function?
Isn't there something like PropTypes.shape ?
Answer the question
In order to leave comments, you need to log in
There is no built-in validation of function parameters in prop types, but you can write a custom validator:
customProp: function(props, propName, componentName) {
if (!/matchme/.test(props[propName])) {
return new Error(
'Проп `' + propName + '` компонента' +
' `' + componentName + '` имеет неправильное значение'
);
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question