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

109
Visualizações
Dynamic src for img tag with javascript

I have a react-app that gets crypto API from some Provider Server and setState in currency variable and shows them in a table. I download each cryptocurrency icon and create a JSON file (cryptoIconSrc) to set img tag src dynamically. icons are SVG. but they don't display on my table.

here I set a condition to find the related icon from the JSON file

currency.map((item) => {
                    let mapItem = item;
                    const temp = cryptoIconSrc.filter((item) => {
                      return item["symbol"] === mapItem["baseAsset"];
                    });

and here I set that related icon to img src

                    <img
                    src={`${temp[0]["src"]}`}
                    width="20px"
                    height="20px"
                    />

but they don't display

I use require("./someDirectory/icon.png") in other sections of my app but in this case require(`${temp[0]["src"]}`) doesn't work and issue an error : module ... not found

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

0

  <img
    src={`${temp[0]["src"]}`}
    key={`${temp[0]["src"]}`}
    width="20px"
    height="20px"
   />

Adding a key prop will do the trick.

about 4 years ago · Juan Pablo Isaza Relatório

0

It seems like you are using back ticks in your code. That almost never works, try using single quotes. So not:

src={`${temp[0]["src"]}`}

But:

src={'${temp[0]["src"]}'}
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