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
Difference between calling a function like <TestFunc /> or <>{TestFunc()}</> in React

I came across something like this in our codebase the other day I got curious. What, if any, is the difference between these methods of calling a function (that returns JSX) in the return method of a React component?

A.)

const TestXYZ = () => {

    const TestFunc = () => {
        return <div>This is some sample text</div>;
    };

    return (
        <>
            <TestFunc />
        </>
    );
};

B.)

const TestXYZ = () => {

    const TestFunc = () => {
        return <div>This is some sample text</div>;
    };

    return <>{TestFunc()}</>;
};

Thanks for your help!

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

This form has significant limitations:

 <>{TestFunc()}</>

First of all, it cannot render class based components, only functional components.

But the bigger problem is that the render does not happen in the context of your view hierarchy. That means no hooks and no access to context.


For extra credit, let's desugar that syntax.

<TestFunc />

Transpiles to:

React.createElement(TestFunc, null)));

This says "React, here is a component, please render it for me". Note how we pass the component, but we don't call it. We let React do that for us.

And:

<>{TestFunc()}</>;

Transpiles to:

React.createElement(React.Fragment, null, TestFunc());

This says "React, here is some JSX I got from a function, please display it." Not how we execute the function ourself and just provide the result to React.

In one case your component is rendered in the context of your application with access to all the perks that offers, and in the other case it does not.

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