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

156
Views
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 answers
Answer question

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 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!