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

237
Views
No anidar expresiones ternarias: forma de cambiar entre 3 estilos según las condiciones

Estoy tratando de mostrar 3 estilos diferentes basados en codiciones, pero no puedo hacerlo usando una expresión ternaria. He encontrado algunas soluciones aquí , pero todavía tengo algunos problemas.
Las siguientes condiciones son las que quería hacer:

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

Porque cuando probé el siguiente código, recibí No anidar expresiones ternarias. 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

Creo que la mejor solución legible es esta:

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

O puede anidar las condiciones:

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