Skip to main content
InterviewHubPRO
Section Overview
Q156

Question 156 of 407

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

38%
React Core & Hooks (407 Qs)•Part 8: Advanced React Patterns, Portals & Performance (152 - 261)

How React PropTypes allow different types for one prop?

mid LevelCode ExampleFormsPerformance

You can use the 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]),
};