How to check multiple Component class types with React PropTypes?

Viewed 79

Assume that I have two components A and B. Then I have another component which takes one of these two.

C.js

import A from './A'
import B from './B'
import PropTypes from 'prop-types'

function C({ Component }) {
  return (
    <div>
      <div>Cool Component</div>
      <Component />
    </div>
  )
}

C.propTypes = {
  Component: PropTypes.oneOfType([A, B])
}

export default C

I have tried the solution above yet it didn't work.

0 Answers
Related