const { id } = useParams();
const [detailData, setDetailData] = useState({});
useEffect(() => {
const q = query(collection(db, "movie"));
onSnapshot(q, (querySnapshot) => {
querySnapshot.docs.map((doc) => {
if (doc.exists) {
setDetailData(doc.data());
} else {
console.log("no doc");
}
})
.catch((error) => {
console.log("Error:", error);`enter code here`
});
});
}, [id]);
how can i pass id of document in this code tried lots of tutorials and official documentation also .
QuerySnapshot.docs returns an array of QuerydocumentSnapshot which has an id field:
https://firebase.google.com/docs/reference/node/firebase.firestore.QueryDocumentSnapshot
This is located outside of the doc.data field. Doc.data contains the data in your DB object.