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

153
Views
I am getting error while calling functions inside mapped array in React JS

Actually I am calling function by mapping over array

let artistId = artist._id;
orderData.products.map((cartproduct, index) => {
const sendOrderData = {
        product: cartproduct._id,
        qty: cartproduct.qty,
      };
  createOrder(userId, sendOrderData).then((data) => {
         if(data.error){
            console.log(data.error)
            }else{
           updateOrderDetails(artistId,sendData).then((response) => {
                if(response.error){
                    console.log(response.error)
                   }else{
                    console.log("done)
                  }
})

But before updateOrderDetails function call is completed for first element the createorder function is called for next element and thus I am not able to update data adequately.

UpdateOrderDetails makes an API call:

export const updateOrderDetailsOfArtist = (artistId, data) => {
  return fetch(`${API}/artist/updateorderdetails/${artistId}`, {
    method: "POST",
    headers: {
      Accept: "application/json",
      "Content-Type": "application/json",
    },
    body: JSON.stringify(data),
  })
    .then((response) => {
      return response.json();
    })
    .catch((err) => console.log(err));
};
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

So, where ever you have the updateOrderDetails(artistId) function written, add async to it.

async function updateOrderDetails(artistId) {
...
// where ever you're using the return statement type await
return await response
}

But for a better answer you need to show what the updateOrderDetails function does, what does it return, what API calls it is doing.

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!