InterviewHubPRO
Section Overview
Q156

Question 156 of 445

Part 8: Advanced React Patterns, Portals & Performance (152 - 261)

35%
React & Modern Frontend (445 Qs)•Part 8: Advanced React Patterns, Portals & Performance (152 - 261)

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:

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