How React PropTypes allow different types for one prop?

You can use oneOfType() method of PropTypes.

For example, the height property can be defined with either string or number type as below:

Component.PropTypes = {
size: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
};

Made in India with ❤️ by Rajesh Kumar Yadav

Twitter