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

153
Views
Add ternary operator instead condition

I would like to add a ternary operator to this code.

 {suggestedTags.length > 0 && (
      <div className={classes.tagSuggestionWrapper}>
        {suggestedTags.map((tag) => {
          return (<div key={tag} 
                       className={classes.tagSuggestion} 
                       onClick={() => { selectTag(tag) }}>{tag}</div>
                       );            
        })}
      </div>
    )}

I'll explain why: I don't need to check > 0 manually because any length more than 0 will be true

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

0

The code below uses ternary:

${suggestedTags.length > 0 ? (
      <div className={classes.tagSuggestionWrapper}>
        {suggestedTags.map((tag) => {
          return (<div key={tag} 
                       className={classes.tagSuggestion} 
                       onClick={() => { selectTag(tag) }}>{tag}</div>
                       );            
        })}
      </div>
    ) : ''}
about 4 years ago · Juan Pablo Isaza Report

0

what about:

Boolean(suggestedTags.length) && (<yourElement/>)

I don't see the need for a ternary unless you have to render something if the length ends up being 0.

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!