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!
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()));
});