【问题标题】:app.default.firebase is not a function errorapp.default.firebase 不是函数错误
【发布时间】:2021-05-10 22:34:51
【问题描述】:

我正在尝试创建一个连接到 Firebase 数据库的 React Native Android 应用程序,当我到达“let cloud = firebase.database();”时出现错误检索数据。

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>;
  }
}

我收到 [未处理的承诺拒绝:TypeError: _app.default.database is not a function。 (在 '_app.default.database()' 中,'_app.default.database' 未定义)] 错误。我该如何解决?

【问题讨论】:

    标签: javascript android firebase react-native


    【解决方案1】:

    你需要导入firebase/database:

    import 'firebase/database";
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-10-23
      • 2013-01-04
      • 1970-01-01
      • 2017-05-09
      • 2021-09-14
      • 2017-02-06
      • 2013-11-04
      • 2015-09-23
      相关资源
      最近更新 更多