I started out with a very simple PropTypes validation:
name: PropTypes.string.isRequired,
Now I need to only have string be required if a certain other condition is false, so:
name: ({name, otherProp}) => {
if (otherProp === 'foo') return null;
if (typeof name === 'string') return null;
return new Error('Error');
}
Which is fine in this case, but what I'd really like to be able to do after the first check is run the regular PropTypes check for string.isRequired inside my custom validator, like maybe:
name: ({name, otherProp}) => {
if (otherProp === 'foo') return null;
return PropTypes.string.isRequired;
}
It seems like there should be a way to do this with PropTypes.checkPropTypes, but I can't figure it out.