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

396
Visualizações
Setting up a counter in a document and then retrieve it using Firestore: Would this be alright or would this be too expensive?

Under the orders collection, I created a document called counts which would store the counts for the status of the orders:

enter image description here

I then created a function to increment the status with "delivered"

And then to display this:

 useEffect(async () => {
    const docRef = doc(db, "orders", "counts");
    const docSnap = await getDoc(docRef);

    if (docSnap.exists()) {
      console.log("Document data:", docSnap.data());
    } else {
      // doc.data() will be undefined in this case
      console.log("No such document!");
    }
  }, []);
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Yes, this is one way to do it I suppose, 'expensive', that's up to you and how many calls you might end up with, as I know Firestore has a limited amount of free document calls.

Another thing is you should not, and I repeat should not make a useEffect asynchronous, the best and right way to perform asynchronous code inside a useEffect would be to declare it inside and then run it like below

useEffect(() => { 
    const AsyncExample = async () => { 
      // async code in here 
    }
    AsyncExample() 
}, [])
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