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

246
Views
Do not nest ternary expressions - Way to change between 3 styles based on coditions

I'm trying to display 3 different styles based on coditions but I cant do it using ternary expression. I've found some solutions here but still having some trouble with it.
The following conditions are the one I wanted to do:

<div className={styles.extraContainer}>
      {
         (() => {
                if (!opened && !followed )
                    <div id={styles.themeBox}><p>+10</p></div>  //show this box
                else if (opened && !followed)
                   <img src={arrowDownIcon} alt="" style={{height:'1.2em', 
                   marginLRight:'10px', width:'auto', objectFit:'contain'}} />   //show this icon
                else  
                   ""     //show nothing
          })()
      }
</div>

Cause when I tried the following code, I received Do not nest ternary expressions. error.

{!opened && !followed ? <div id={styles.themeBox}><p>+10</p></div> : (opened && !followed ? <img src={arrowDownIcon} alt="" style={{height:'1.2em', marginLRight:'10px', width:'auto', objectFit:'contain'}} /> : ""}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I think that best readable solution is this:

<div className={styles.extraContainer}>
      {!opened && !followed &&
        <div id={styles.themeBox}><p>+10</p></div>  //show this box
      }
      {opened && !followed &&
       <img src={arrowDownIcon} alt="" style={{height:'1.2em', 
                   marginLRight:'10px', width:'auto', objectFit:'contain'}} />  //show this icon
      }
</div>

Or you can nest the conditions:

<div className={styles.extraContainer}>
      {!followed && <>
       {!opened &&
        <div id={styles.themeBox}><p>+10</p></div>  //show this box
       }
       {opened && 
        <img src={arrowDownIcon} alt="" style={{height:'1.2em', 
                   marginLRight:'10px', width:'auto', objectFit:'contain'}} />  //show this icon
       }
   </>}
</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!