Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

183
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!