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

97
Visualizações
Use data from an array as src path for an img

I receive an array like this from the backend :

['test.jpg', 'test2.jpg']

I put it into a React state named pictures.

What I need to do is to map on it, and for each picture name in the array, create an img with that name as variable in the path like this :

{pictures.map((picture) => (
<img
className="picture"
src={`http:localhost:8000/pictures/${ WHAT DO I NEED TO WRITE HERE ? }/>

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

0

The first argument from the map function refers to each item in your array, so name it whatever you want and you get the item from the array.

Since you have named it picture, the name of the each item is now picture

Briefly, you can put picture in the space as:

{pictures.map((picture) => (
  <img
    className="picture"
    src={`http:localhost:8000/pictures/${picture}`}/>
 ))}
about 4 years ago · Juan Pablo Isaza Relatório

0

In this case you would just need to add http:localhost:8000/pictures/${picture}

Of course this will only work as long as there is an image with a matching name on port 8000

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