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

105
Views
React use parameters in jsx variable

I'm new to react and I'm trying to substitute a part of a jsx return I'm repeating in a react component, but there are slight differences in each repetition so I want to pass a simple boolean as a parameter to the variable so I can check those inside jsx. Here is what I've done so far:

function links(condition){
   console.log("Condition is: " + condition);
   return(<h1 className={`mr-10  ${ condition === true ? 'flex' : 'hidden' }`>Test</h1>);
}

const Navbar = () => { 
   return( <nav>
       <div> {links.call(false)} </div> 
       <div> {links.call(true)} </div>
   </nav> 
); }

This returns Condition is: then Condition is: Undefined in the console. How can I achieve this?

almost 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Down there you can see the "proper" way of using react:

function Links({ condition }) {
  return(
    <h1 className={`mr-10  ${ condition === true ? 'flex' : 'hidden' }`>
      Test
    </h1>
  );
}

const Navbar = () => { 
  return(
    <nav>
      <div>
        <Links condition={false} />
      </div> 
      <div>
        <Links condition={true} />
      </div> 
    </nav> 
  );
}

Note:

  • Better call you component with a caps: link => Link
  • To call a component use <Component {...props} />
  • The props (parameters) are passed as a object in the first parameter of the function
almost 4 years ago · Santiago Trujillo 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!