Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

106
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda