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

375
Vistas
Firebase React (native) get documents by reference field

I have created 3 tables in firebase console. Event, occurrence and venue. Now an event can have multiple occurrences, as occurrences are basically shows.

In occurrence document I have event set as reference and venue set as reference.

I query firebase through occurrence to get all the latest shows.

I want to build an array of javascript objects in react that will have id, date (comes from occurrence), title (comes from event) and address (comes from venue).

const [events, setEvents] = useState<any[]>([]);

useEffect(() => {
   const subscribe = firestore()
      .collection('occurrences')
      .onSnapshot(querySnapshot => {
        const showList: any[] = [];

        querySnapshot.forEach(documentSnapshot => {
          const { startDate, event, venue } = documentSnapshot.data();

          const show: any = {
            id: documentSnapshot.id,
            date: startDate,
          };

          event.onSnapshot(
            eventsDocSS => {
              show.title = eventsDocSS.get('name');
            },
            error => console.error('my error', error)
          );

          venue.onSnapshot(
            eventsDocSS => {
              show.address =
                eventsDocSS.get('addressLocality') + ', ' + eventsDocSS.get('addressRegion');
            },
            error => console.error('my error', error)
          );

          showList.push(show);
        });

        setEvents(showList);
      });

    return subscribe()
},[])

This code mind you does not work as I would need to run the event and venue snapshots async to make it work. But if I make it async I have cascade it all the way out at least to forEach loop, which does not work as subscribe cannot be async.

I am using @react-native-firebase/firestore but the code should not be that different in syntax.

How do I get setEvents populated with correct data?

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