1 min readAug 15, 2018
Hi Dennis Riungu, this is the best way that I found, to initialize firebase.
As official doc mentioned, centralizing all firebase related function into ONE single file, and export it.
export const DB = firebase.database()export default firebase
This avoids creating multiple firebase.database() //or auth
instances.
import * as firebase from 'firebase'
import 'firebase/auth/dist/index.cjs'
import 'firebase/firestore/dist/index.cjs'
import 'firebase/database/dist/index.cjs'const config = { apiKey: 'foo', authDomain: 'foo', databaseURL: 'foo', projectId: 'foo', messagingSenderId: 'foo', storageBucket: 'foo',}if (!firebase.apps.length) {
firebase.initializeApp(config)
}export const auth = firebase.auth()
export const DB = firebase.database()
export default firebase