Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

231
Visualizações
How to properly import firebase module in React JS to initializeApp

I'm trying to initialize a firebase app but I don't understand how or where to call it.

I have a file name fire.tsx and inside it there's a call to firebase's initializeApp. But now what? How do I include this in my app?

I thought just by adding import { firebaseApp, firebaseAnalytics } from './fire'; to the top of App.tsx it would work but apparently it doesn't. Am I doing this wrong?

import firebase from "firebase";
import "firebase/auth";
import { initializeApp } from "firebase/app";
import { getAnalytics } from "firebase/analytics";


const firebaseConfig = {
  apiKey: "xxx-xx-xx",
  authDomain: "xxx-xx-xx",
  databaseURL: "xxx-xx-xx",
  projectId: "xxx-xx-xx",
  storageBucket: "xxx-xx-xx",
  messagingSenderId: "xxx-xx-xx",
  appId: "xxx-xx-xx",
  measurementId: "xxx-xx-xx"
};

const firebaseApp = initializeApp(firebaseConfig); 
export default firebaseApp;

export const firebaseAuth = firebase.auth();

export const firebaseAnalytics = getAnalytics(); 

App.tsx

import { firebaseApp, firebaseAnalytics } from './fire';

Firebase Error

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Use the new Modular SDK only because the compat version would be removed in future updates. Try refactoring the code this way:

import { initializeApp } from "firebase/app";
import { getAuth } from "firebase/auth";
import { getAnalytics } from "firebase/analytics";


const firebaseConfig = {
  apiKey: "xxx-xx-xx",
  authDomain: "xxx-xx-xx",
  databaseURL: "xxx-xx-xx",
  projectId: "xxx-xx-xx",
  storageBucket: "xxx-xx-xx",
  messagingSenderId: "xxx-xx-xx",
  appId: "xxx-xx-xx",
  measurementId: "xxx-xx-xx"
};

const firebaseApp = initializeApp(firebaseConfig); 

export const firebaseAuth = getAuth(firebaseApp);
export const firebaseAnalytics = getAnalytics(firebaseApp); 

The new Modular SDK checks if a default instance is already create so you don't have to like in previous versions.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda