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

160
Visualizações
Inserting image tag inside a template literal

I'm trying to insert an image depending on a state - but this will display the string of img src=${redExclamation} .

return `${
    isEmpty
        ? `<img src=${redExclamation} />`
        : `<img src=${greenCheck} /> `
    }`;

I've tried it a different way where i got rid of the string literal:

return `${
    isEmpty
        ? <img src=${redExclamation} />
        : <img src=${greenCheck} />
    }`;

But this will show [object Object] in the HTML. Not sure what I should be doing here. Any help would be appreciated!

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

you are returning a string, not html.

return isEmpty
        ? <img src={redExclamation} />
        : <img src={greenCheck} />;

Might be what you need

about 4 years ago · Juan Pablo Isaza Relatório

0

You can try without the outer literal like the following:

return isEmpty ? `<img src=${redExclamation} />` : `<img src=${greenCheck} />`

Or if you're trying to return a jsx you should do it as per docs

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