我试图将firebase与React-Native project.firebase的配置文件连接起来
firebase.js
import * as firebase from "firebase/app";
import "firebase/firestore";
const config = {
apiKey: "A***********************0",
authDomain: "gu***********************m",
databaseURL: "ht*******************m",
projectId: "g*****2",
storageBucket: "g********om",
messagingSenderId: "########",
appId: "####################",
measurementId: "****************"
};
firebase.initializeApp(config);
export const db = firebase.firestore();
Home.js
import { db } from '../config/firebase';
export default function Home() {
var temp = {
fruit: "apple",
name: "banana"
};
db.collection('books').add(temp);
console.log("after adding to db");
var db1 = db.collection('books').get(temp);
console.log("hello dude");
console.log(db1);
console.log("bye dude");
}
[我在android中刻录应用程序后,它显示红色屏幕并显示错误:
ReferenceError Can't find variable: crypto
This error is located at:
in Home (at App.js:7)
in gullak (at renderApplication.js:45)
in RCTView (at AppContainer.js:109)
in RCTView (at AppContainer.js:135)
in AppContainer (at renderApplication.js:39)
我无法添加到Firestore数据库中。我在这里缺少什么吗?请帮助我。谢谢。
问题是,您正在为node.js使用firebase。加密软件包是nodejs环境的一部分,但您不能在react native应用中使用它。
要在React Native中使用firebase,请查看此包react-native-firebase。