Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

159
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda