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

166
Views
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 answers
Answer question

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 Report
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!