Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

172
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda