• Empleos
  • Sobre nosotros
  • profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
  • empresas
    • Inicio
    • Publicar vacante
    • Nuestro proceso
    • Precios
    • Pruebas Online
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

203
Vistas
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!");
    }
  }, []);
almost 3 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

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() 
}, [])
almost 3 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recomiéndame algunas ofertas
Necesito ayuda