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

108
Views
Representar className con instrucción If Els ternaria anidada React

Tengo un pequeño problema. Necesito representar un nombre de clase en función de algunas condiciones. Tengo un botón Play, un botón Live y botones generales. La mayoría de las clases son iguales, pero necesito agregar una clase adicional a un botón de reproducción.

Mi código hasta ahora se ve así:

 className={`"Controller-Button player-btn icon" ${ isSelected ? `${btnName === "PLAYER_LIVE" ? " live-button" : ""}` : `${btnName === "PLAYER_LIVE" ? " live-button" : ""}` }`}

Y ahora estoy atascado. Necesito agregar una condición adicional antes de isSelecetd: btnName === "PLAYER_PLAY" ? " play-button" : "" pero tengo un problema sobre cómo poner esto correctamente en dicho renderizado. ¿Si btnName === "PLAYER_LIVE" ? " live-button" : "play-button" esta clase estará en todos los botones.

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

0

Puedes usar algo como eso:

 const classes = ["Controller-Button", "player-btn", "icon"]; if(isSelected) { classes.push("live-button") } else if(somethingCondition) { classes.push("someClass") }

etc...

 className={classes.join(' ')}
about 4 years ago · Juan Pablo Isaza Report

0

Sugeriría mover esta lógica a una función. Algo como

 const getClassName = () => { let className if (btnName === 'PLAYER_PLAY') { // applicable logic here for className here } else { // applicable logic here for className here } return className }
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!