Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase v9 version of firebase.apps.length

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?

like image 512
Shivam Avatar asked Oct 28 '25 05:10

Shivam


1 Answers

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
}
like image 181
Shivam Avatar answered Oct 30 '25 22:10

Shivam