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

168
Vistas
How do I access firestore documents with the modular sdk and react?

Any help would be greatly appreciated! I've recently run into trouble with firebase that forced me to use the modular sdk, however I'm fairly new to firebase and programming in general. I recently used:

useEffect(() => {
  db.onSnapshot((snapshot) => {
    setPosts(snapshot.docs.map((doc) => doc.data()));
  });
}, []);

But with this new Module not found. Unable to resolve 'firebase', error that I keep getting, I tried the new modular sdk. I currently have:

 useEffect(() => {
    const helper = async () => {
      const docRef = collection(db, 'posts');
      const docSnap = await getDocs(docRef);
      console.log(docSnap.docs);
    };
    helper();
  }, []);

But this only returns undefined, along with docSnap.data and other options. Any and all help would be appreciated, thank you!

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

This code in the v8 SDK:

db.onSnapshot((snapshot) => {
  setPosts(snapshot.docs.map((doc) => doc.data()));
});

Is the exact same as this in the modular v9 SDK:

onSnapshot(db, (snapshot) => { // 👈 change is here
  setPosts(snapshot.docs.map((doc) => doc.data()));
});

The db in here looks a bit weird though, so it might actually have to be:

onSnapshot(collection(db, 'posts'), (snapshot) => { // 👈 change is here again
  setPosts(snapshot.docs.map((doc) => doc.data()));
});
about 4 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 Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda