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

394
Views
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 answers
Answer question

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 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!