Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

180
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda