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

185
Vistas
Calling out to an API for each element in an array

I have an array of objects. Each object is a profile of a dog including name, breed, etc. I want to be able to map through the array, get the breed of dog, and call out to an API for a random image of that breed. Below is a portion my React code that I tried (and failed). To my understanding, it's not working because useEffect only will call out once even though I'm mapping through the array. It is possible to call out for each breed I map through?

    const urlDogBase = "https://dog.ceo/api/breed/"
    const urlEnding = "/images/random"
    const [dogImage, setDogImage] = useState({})

    let availableDogs = DogData.map((dog,index) => {
        const dogUrl = dog.breed
        const fullUrl = `${urlDogBase}${dogUrl}${urlEnding}`

        useEffect(()=>{ 
            fetch(fullUrl)
              .then((response) => response.json())
              .then((data) => setDogImage(data.message))
              .catch(() => console.log("oops error"));
          }, []);

        return(
            <img src={dogImage} />
        )
    })
about 4 years ago · Juan Pablo Isaza
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