【发布时间】:2022-01-07 14:40:20
【问题描述】:
这是我的firebase.js
import { initializeApp } from "firebase/app";
import { getFirestore } from "firebase/firestore";
import { getAuth } from "firebase/auth";
import { getAnalytics, logEvent, isSupported } from "firebase/analytics";
// Update the config
var firebaseConfig = {
// ...Update config
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
const firestore = getFirestore(app);
const auth = getAuth();
const analytics = getAnalytics(app);
// Uncomment the following if you want to use emulator
// if (process.env.NODE_ENV === "development") {
// firestore.useEmulator("localhost", 8080);
// auth.useEmulator("http://localhost:9099");
// }
export { app, firestore, auth, analytics };
这就是我在我的一个组件中使用它的方式-
import { app, firestore, auth } from "../../firebase";
const linksPathRef = useMemo(
() => firestore.collection("users").doc(userUid).collection("links"),
[userUid]
);
但我收到firestore.collection is not a function 错误。不确定,我哪里出错了。
项目中安装的firebase版本"firebase": "^9.6.1"
【问题讨论】:
-
@Dharmaraj nope 已经尝试过了。没有运气。
-
您的代码仍然采用名称空间语法(如您的问题所示)。您能否分享您从该答案中尝试过的内容?
-
您能否从我的代码角度考虑一下?
-
您使用的是最新的 firebase SDK,它不再支持点符号,而是包含函数式编程。请仔细查看 firebase 文档firebase.google.com/docs/firestore/query-data/get-data
标签: javascript reactjs firebase google-cloud-firestore react-hooks