Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

104
Vistas
Render className with ternary nested If Els statement React

I do have a small issue I do need to render a className based on few conditions. I have a Play button, Live button and general buttons. Most classes are the same, but I do need to add extra class to a play button.

My code so far is looking like this:

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

And now I am stuck. I need to add extra condition before isSelecetd: btnName === "PLAYER_PLAY" ? " play-button" : "" but i do have issue how properly put this in such render. If I will add btnName === "PLAYER_LIVE" ? " live-button" : "play-button" this class wil be in all buttons.

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You can use something like that:

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 Denunciar

0

I would suggest to move this logic into a function. Something like

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda