名为'[DEFAULT]'的Firebase应用程序已存在REACT [英] Firebase App named '[DEFAULT]' already exists REACT

查看:118
本文介绍了名为'[DEFAULT]'的Firebase应用程序已存在REACT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是React的初学者,目前我尝试将我的第一个应用程序连接到Firebase数据库。

I'm a beginner in React and at the moment I try to connect my first app to a Firebase database.

我有两个文件。第一个是config.js文件,其中存储了有关数据库的所有信息,如下所示:

I have two files for that. The first, is a config.js file where all the information about the database are stored, like this:

`export default {
    apiKey: "***",
    authDomain: "***",
    databaseURL: "***",
    projectId: "***",
    storageBucket: "***",
    messagingSenderId: "***"
  };`

和我的另一个文件,App.js:

And my other file, App.js:

`import React, { Component } from 'react';
import './App.css';

//Firebase
import * as firebase from 'firebase';
import config from 'firebase';


class App extends Component {
constructor () {
    super()

    this.state = { loading: true }
    firebase.initializeApp(config)
  }

  componentWillMount () {
    const capsRef = firebase.database().ref('Capsules')

    capsRef.on('value', snapshot => {
      this.setState({
        Capsules: snapshot.val(),
        loading: false
      })
    })
  }

  render () {
    if (this.state.loading) {
      return (
        <p>Je suis en train de charger.</p>
      )
    }

    const capsRef = Object.keys(this.state.tweets).map(key => {
      return <p key={key}>{this.state.Capsules[key].designation}</p>
    })

    return (
      <div>


        <h1>Test</h1>

      </div>

    )
  }
}

export default App;`

因此,当我刷新浏览器时,我收到一条错误消息:Firebase:Firebase App命名'[DEFAULT]'已经存在(app / duplicate-app)。

So, when I refresh my browser, I have an error message : "Firebase: Firebase App named '[DEFAULT]' already exists (app/duplicate-app)."

任何人都可以帮助我吗?
现在已经过了一个星期,我正在寻找自己的解决方案。

Can anyone help me ? It's been a week now that I'm looking for a solution by myself.

推荐答案

很难说没有看到您的代码,但您可以尝试:

Hard to tell without seeing your code, but you could try:

if (!firebase.apps.length) {
  firebase.initializeApp(config);
}

这篇关于名为'[DEFAULT]'的Firebase应用程序已存在REACT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆