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

161
Visualizações
How come a JSX element accepts a method with parenthesis vs without it as its child?

How come when I try to pass in a method without parenthesis, into a React component as a child of one of the JSX elements, I get an error in the console, but as soon as I add parenthesis, it's all fine and dandy?

For ex:

randomFunction(){
//do something here
}

This gives me an error: <div>{this.randomFunction}</div>

But this doesn't. <div>{this.randomFunction()}</div>

What adds to my confusion is because of the way methods are called when used as a prop. We don't use the parenthesis then.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

this.randomFunction returns the function itself

this.randomFunction() actually calls (executes) the function

A function is not a valid JSX element, but the return from an executed function is.

So if:

function randomFunction() {
  return <div><div>
}

And you call:

<div>{this.randomFunction()}<div>

The function will succeed

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