1if (!firebase.apps.length) {
2 firebase.initializeApp({});
3}else {
4 firebase.app(); // if already initialized, use that one
5}
6
1// Config file
2import * as firebase from "firebase";
3
4const config = {...};
5
6export default !firebase.apps.length ? firebase.initializeApp(config) : firebase.app();
7
8// Other file
9import firebase from '../firebase';
10...
11console.log(firebase.name);
12console.log(firebase.database());
1// Config file
2import * as firebase from "firebase";
3
4const config = {...};
5
6export default !firebase.apps.length ? firebase.initializeApp(config) : firebase.app();
7
8// Other file
9import firebase from '../firebase';
10...
11console.log(firebase.name);