Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

165
Views
How to type a higher order component with flow

I have the following HOC:

export default (keys: Array<string>) =>
  (WrappedComponent: React.Component<*, *, *>) => (props: Object): React.Element<*> => {
    if (hasNotYetLoadedProps(keys, props)) {
      return (
        <div
          style={{
            textAlign: 'center',
            display: 'flex',
            justifyContent: 'center',
            alignItems: 'center',
            height: '100%',
          }}
        >
          <div>Loading</div>
        </div>
      )
    }
    return <WrappedComponent {... props} />
  }

that either render the original component or a loading indicator. With the actual flow type declaration I get this error:

React element `WrappedComponent`. Expected React component instead of React$Component 

in the last line. What would be the correct type of the incoming component?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

The type needs to ReactClass<any>

export default (keys: Array<string>) =>
  (WrappedComponent: ReactClass<any>) => (props: Object): React.Element<*> => {
    if (hasNotYetLoadedProps(keys, props)) {
      return (
        <div
          style={{
            textAlign: 'center',
            display: 'flex',
            justifyContent: 'center',
            alignItems: 'center',
            height: '100%',
          }}
        >
          <div>Loading</div>
        </div>
      )
    }
    return <WrappedComponent {... props} />
  }
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!