我不断收到此错误 Firebase: Firebase App named '[DEFAULT]' already exists (app/duplicate-app) [英] I keep getting this error Firebase: Firebase App named '[DEFAULT]' already exists (app/duplicate-app)
问题描述
import React, { Component } from 'react'
import './App.css';
import "bootstrap/dist/css/bootstrap.min.css";
import firebase from 'firebase/app';
import 'firebase/database';
import ThreadDisplay from './ThreadDisplay/components/ThreadDisplay';
class google extends Component {
constructor(props) {
super(props);
const config =
{
apiKey: "",
authDomain: "",
projectId: "",
storageBucket: "",
messagingSenderId: "",
appId: "",
measurementId: ""
};
this.app = firebase.initializeApp(config);
this.database = this.app.database();
}
render() {
return (
<ThreadDisplay database={this.database} />
);
}
}
export default google;
我只初始化了一次 firebase 应用程序,然后我一次又一次地收到此错误.Firebase:名为[DEFAULT]"的 Firebase 应用已经存在(app/duplicate-app).那么我该如何解决这个问题
I am initializing firebase app only one Time then I am getting this error again and again. Firebase: Firebase App named '[DEFAULT]' already exists (app/duplicate-app). so how do I solve this
推荐答案
如果这是您调用 initializeApp
的唯一地方,则可能是该组件被多次创建.
If this is the only place you call initializeApp
, it might be that the component is created multiple times.
如果你找不到保证只被调用一次的点,我通常发现最简单的方法是明确检查我们之前是否已初始化 Firebase:
If you can't find a spot that is guaranteed to be called only once, I usually find it easiest to explicitly check if we're initialized Firebase before with:
if (firebase.apps.length === 0) {
this.app = firebase.initializeApp(config);
this.database = this.app.database();
}
这篇关于我不断收到此错误 Firebase: Firebase App named '[DEFAULT]' already exists (app/duplicate-app)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!