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

74
Views
React JS Mapped Data Fecthing

I am trying to make a web app and I am fetching data from some where as an array. I got urls from this array in each element. So I could not imagine how I should fetch data from the mapped urls.

 useEffect(() => {
    axios
      .get(`someurl`)
      .then((response) => setState(response.data));
  }, []);

I am fetching basically as above and putting the response in some state.

[{
    "userId": 1,
    "id": 1,
    "title": "delectus aut autem",
    "completed": false,
    "url": "fakeapi.com/user/1"
},
{
    "userId": 2,
    "id": 2,
    "title": "delectus aut autem",
    "completed": false,
    "url": "fakeapi.com/user/2"
}]

Then I am mapping the response and listing in table. I want to fetch again via urls in response. I could not understand how should I do because I am putting each response in a state.How should I do it? Thanks in advance!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

This code get the user list first and then get the individual user info using the response.data url by the loop. Then finally it set to the setstate

   axios
          .get(`someurl`)
          .then(async (response) => {
            await response.data.map(async (data, index) => {
              await axios
               .get(data.url)
               .then((resp) => response.data[index].user_data = resp.data );
             })
             console.log(response.data)
             setState( prevData => [...prevData, response.data] );
          })
about 4 years ago · Juan Pablo Isaza Report
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!