[英]app.default.firebase is not a function error
I am trying to create a React Native Android app that connects to a Firebase database and getting an error when I get to "let cloud = firebase.database();"我正在尝试创建一个 React Native Android 应用程序,该应用程序连接到 Firebase 数据库,当我到达“let cloud = firebase.database(); to retrieve the data.
检索数据。
import { Container, Header, Title, Content, Body, Text, Button, View, H3, Table, Row, Col } from 'native-base';
import React from "react";
import 'firebase/firestore';
import 'firebase/auth';
import firebase from "firebase/app";
const FirebaseConfig = {
apiKey: "xxx",
appId: "xxx",
projectId: "xxx",
authDomain: "xxx",
databaseURL: "xxx",
storageBucket: "xxx",
messagingSenderId: "xxx",
}
export default class Chat extends React.Component {
constructor(props) {
super(props);
this.state = {
people: [],
}
}
async initializeFirebase(){
if (firebase.apps.length) {
await firebase.app().delete();
}
firebase.initializeApp(FirebaseConfig);
}
async componentDidMount(){
this.initializeFirebase();
let cloud = firebase.database();
}
render() {
return <Container>
<Content>
<Body>
<Text>Testing</Text>
<Text>{this.state.people.length}</Text>
</Body>
</Content>
</Container>;
}
}
I'm getting the [Unhandled promise rejection: TypeError: _app.default.database is not a function.我收到 [Unhandled promise 拒绝:TypeError: _app.default.database is not a function。 (In '_app.default.database()', '_app.default.database' is undefined)] error.
(在 '_app.default.database()' 中,'_app.default.database' 未定义)] 错误。 How do I solve this?
我该如何解决这个问题?
You need to import firebase/database
:您需要导入
firebase/database
:
import 'firebase/database";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.