// Necessary Imports
import { useEffect, useState } from "react";
import { db } from "relative path of your firebase config file";
import { collection, onSnapshot } from "firebase/firestore";
// Code inside component
const [data, setData] = useState([]);
useEffect(
() =>
onSnapshot(collection(db, "collectionName"), (snapshot) => {
setData(
snapshot.docs.map((doc) => {
return { ...doc.data(), id: doc.id };
})
);
}),
[]);
console.log(data);
const collectionRef = collection(db, "DATA-COLLECTION");
const docSnap = (async () => await getDocs(collectionRef))();
useEffect(() => {
docSnap.then((data) => {
data.forEach((doc) => {
console.log('doc: ', doc);
console.log(doc.data());
});
});