I have the following helper function in React:
import { getAuth } from 'firebase/auth';
import { initializeApp } from 'firebase/app';
import { getFirestore, collection, doc, addDoc, getDoc, setDoc, getDocs, query, where } from 'firebase/firestore';
import { getStorage, ref } from 'firebase/storage';
import { FIREBASE_API } from '../config';
const firebaseApp = initializeApp(FIREBASE_API);
const auth = getAuth(firebaseApp);
const db = getFirestore(firebaseApp);
const storage = getStorage();
export function getDocuments(col) {
const colRef = collection(db, col);
const q = query(colRef, where('uid', '==', auth.currentUser.uid));
getDocs(q).then((snap) => {
console.log(snap);
return snap?.data();
});
return [];
}
Where I am trying to return the documents for a given collection. This is my console output:
I am trying to figure out why the data() method is not available for me to use.. it is a Firestore Database (not Realtime).
Am I doing something wrong?
