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

245
Views
Conditional statements to show a different component React js

i want to create a function or a conditional statement you can say that can show different components based on "If the user have bought products" then show the products components otherwise show "just a simple text like browse or buy products."

 <div>
 <Bookscard />
 </div>

so this is my component, inside the component the purchased products are being mapped. Can i get a conditional statement that can either show this component like ( if user.courses is greater than or equal to 1 then show the component otherwise show a text ) something like this

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You can try this:

<div>
 { user.courses.length > 0 &&
 <Bookscard />
 }
 { user.courses.length > 0 ||
 <NoResults />
 }
</div>

Or you can keep consistency with && by:

<div>
 { user.courses.length > 0 &&
 <Bookscard />
 }
 { user.courses.length == 0 &&
 <NoResults />
 }
</div>
about 4 years ago · Juan Pablo Isaza Report

0

Adding up to @Antoine Baqain's answer, you could use ternary operator too, like this:

<div>
 { user?.courses?.length > 0 ? <Bookscard /> : <NoResults /> }
</div>
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!