Reputation: 33
My friend wrote this code last year, Now that firebase v9 has some syntax changes, its not working anymore. What changes should i make -
useEffect(() => {
const colRef = collection(db, 'movies',doc(id))
colRef.doc(id)
.get()
.then((doc) => {
if (doc.exists) {
setDetailData(doc.data());
} else {
console.log("No such document in firebase 🔥");
}
})
.catch((error) => {
console.log("Error getting the document: ",error);
});
}, [id]);
The problem is in the colRef.doc(id) section
Upvotes: 0
Views: 78
Reputation: 83103
You'll find the solution in the documentation in the "Get a document" section (Tab "Web version 9").
import { doc, getDoc } from "firebase/firestore";
useEffect(() => {
const docRef = doc(db, "movies", id);
getDoc(docRef)
.then((doc) => {
if (doc.exists()) {
setDetailData(doc.data());
} else {
console.log("No such document in firebase 🔥");
}
})
.catch((error) => {
console.log("Error getting the document: ", error);
});
}, [id]);
Upvotes: 1