Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

101
Vistas
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
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 Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda