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

115
Views
How to reload the page after a Firebase delete request has executed

I have a method that sends a delete request to my Firebase collection. I want the page to reload after the delete request has gone through and the doc is deleted. As it is now, the page reloads immediately and the doc doesn't delete but it works fine if I remove the reload part of the code.

async deletePost() {
  database.collection("posts").where("id", "==", this.id).get().then(data => {
    data.forEach(doc => {
      doc.ref.delete()
    })
  }).then(() => {
    M.toast({
      classes: "toast-alert",
      html: "Post deleted"
    })
  }).then(
    window.location.reload()
  )
}

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

0

Each delete() call is asynchronous, so you need for all of them to complete. The solution for this is to use Promise.all on the return values you get from delete():

async deletePost() {
  return database.collection("posts").where("id", "==", this.id).get().then(data => {
    const promises = data.docs.map(doc => doc.ref.delete());
    return Promise.all(promises);
  }).then(() => {
    window.location.reload()
  )
}
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!