Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

122
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda