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

100
Views
chakra ui table not generating with content returned from firestore query - useState react

having issue with my react users table not rendering on the initial render in the browser. userList appears to be running behind and I assume that is due to an async issue with setState(). if anyone has any suggestions to tweak this to fire get the state synced up so my content appears

i am using firestore

the code grabs a 'currentBizId' from the current users info, uses that value as a parameter in a document reference in a separate collection, grab that new document, looks at an array of userIds, then goes and grabs the userIds user docs and displays them in a table.

Hopefully that makes sense, let me know if you have any questions!

  useEffect(() => {
    if (currentBizId) {
      const bizDocRef = doc(firestore, "businesses", currentBizId);
      let unSubArr: any = [];
      const unsub = onSnapshot(bizDocRef, (bizDoc: any) => {
        const adminIds = bizDoc.data()!.admins;
        const adminData: any = [];
        unSubArr = adminIds.map((user: any) => {
          const adminDocRef = doc(firestore, "users", user);

          return onSnapshot(adminDocRef, (userDoc: any) => {
            adminData.push(userDoc.data()!);
          });
        });
        console.log(adminData);
        setUserList(() => adminData);
      });
      return () => {
        unsub();
        unSubArr.forEach((unsub: any) => {
          unsub();
        });
      };
    }
  }, [currentBizId]);
about 4 years ago · Juan Pablo Isaza
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!