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

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

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