我的朋友去年寫了這段代碼,現在 firebase v9 有一些語法變化,它不再起作用了。我應該做什么改變 -
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]);
問題出在 colRef.doc(id) 部分
uj5u.com熱心網友回復:
您將在 “獲取檔案”部分(選項卡“Web 版本 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]);
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/537459.html
標籤:Google Cloud Collective javascript火力基地google-cloud-firestore
