In a React application, I usually initialize firebase like this:
if (firebase.apps.length < 1) {
firebase.initializeApp(firebaseConfig);
// Initialize other firebase products here
}
This worked perfectly until I upgraded to v9 beta. How do I make it work for the new version?
The correct way to do it is to use getApps():
import { getApps, initializeApp } from "firebase/app";
if (getApps().length < 1) {
initializeApp(firebaseConfig);
// Initialize other firebase products here
}
A simple solution that has worked for me for v9 is this:
import { initializeApp } from "firebase/app";
let firebase;
if (!firebase) {
firebase = initializeApp(config)
}