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

296
Views
Reaccionar: ¿cuál es la forma correcta de recargar después de que se realizan varias solicitudes de axios?

Me pregunto cuál es la mejor manera de realizar múltiples solicitudes de axios y volver a cargar la página una vez completada.

Si usa el camino a continuación, la página se volverá a cargar antes de que se completen todas las solicitudes de axios

 const handleDeletePost= async (postId) => { //delete multiple posts let postToBeDeleted = selectedPostId; // it's an array containing the id of selected posts if (postToBeDeleted.length > 0) { postToBeDeleted.forEach(async (id) => { const response = await PostService.deletePost(id); console.log(response); }); window.location.reload(); // if I put it here, the page will reload before the delete completes } };
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Puede usar Promise.all para obtener solicitudes en paralelo sin esperar a que finalice cada una:

Además, primero debe esperar a que se complete y luego volver a cargar la página.

 const handleDeletePost = async (postId) => { const postToBeDeleted = selectedPostId; if (postToBeDeleted.length > 0) { const promises = []; postToBeDeleted.forEach((id) => { promises.push(PostService.deletePost(id)); }); await Promise.all(promises).then((values) => { console.log(values); }); window.location.reload(); } };
about 4 years ago · Juan Pablo Isaza Report

0

El problema parece ser que espera que cada iteración espere en cada iteración. Sin embargo, las funciones forEach y async no funcionan bien juntas. En su lugar, debe usar algo como Promise.all.

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!