因此,我有一个简单的 React Native 应用程序,它是我使用 Expo 创建的,并在我的个人 Android 设备上进行调试。
我已将 firebase/firestore 包含到我的应用程序中,现在尝试在单击按钮时将对象添加到 firestore 。
这是我的代码:
firebaseConfig.js :
import { initializeApp } from '@firebase/app';
var config = {
...
}
const app = initializeApp(config);
export default app;
成分:
从 '../firebaseConfig' 导入 { app } ;
从 'firebase/firestore/lite' 导入 { getFirestore };
从“firebase/firestore”导入{ doc、setDoc、collection、query、where、getDocs、initializeFirestore };
...
导出默认函数 Component() {
const firestoreDb = getFirestore(app);
// this function is called when clicking a button
const onAddListPress = () => {
setDoc(doc(firestoreDb, "cities", "LA"), {
name: "Los Angeles",
state: "CA",
country: "USA"
});
}
}
这会引发以下错误:
Expected first argument to collection() to be a CollectionReference, a DocumentReference or FirebaseFirestore
上面的代码(在 onPress 中)是从官方 firestore 文档复制的,此处:https://firebase.google.com/docs/firestore/manage-data/add-data#set_a_document
有谁知道为什么这不起作用?