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

184
Views
Function as property in React.js + TypeScript component

What are the differences between this syntax? What types will they have?

eg:

const foo = () => (<>Something...</>);  

const bar = (arg: string) => (<>{arg}</>);

interface IComponent {
property: ???
}

<Component property={foo} />
<Component property={foo()} />
<Component property={() => foo} />
<Component property={() => foo()} />
<Component property={() => bar(arg)} />
<Component property={bar(arg)} />
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

When you are trying to set a React Component as a property you should go with ReactElement or ReactNode. These types can be imported by the react component.

Also then only your first definition is valid. (Okay Maybe second and last one too, but that is not what you really want.

Your result:

property: ReactElement

Definition 3 is function that returns a function, so the valid syntax should be:

property: () => () => ReactElement<{args: string}>

Definition four and five is a simpler for. It directly returns a React Node:

property: () => ReactElement or
property: () => ReactElement<{args: string}>

It depends how your component should look like :)

about 4 years ago · Juan Pablo Isaza 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!