Palisand Palisand - 5 months ago 63
React JSX Question

PropTypes component checking equivalent in Flow

Given the following code using PropTypes (see this issue)

const SomeComponent = ({comp}) => {...}

SomeComponent.propTypes = {
comp: PropTypes.shape({
type: PropTypes.oneOf([SomeOtherComponent])

what is the equivalent using Flow types?

I've only gotten as far as:

const SomeComponent = ({comp}: {comp: React$Element<any>}) => {...}

using this for reference, but that will allow
to be any React component.

How do I type-check a prop to ensure it is an instance of a specific React component using Flow?

Answer Source

As of Flow 0.53, this can be done using React.Element<typeof Component>.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download