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

286
Visualizações
firebase.database.ref is not a function React Native / Expo

I am pretty new to expo and firebase, and I have this error that I have no idea what the issue is. I am trying to fetch photos from firebase database. I know for sure the issue is not with firebase config because I can upload photos into firebase storage.

I suspect the issue is with exporting and importing firebase.

This is the error message I am getting :

[TypeError: _firebase.db.ref is not a function. (In '_firebase.db.ref('users/photos')', '_firebase.db.ref' is undefined)]

Note: I am using firebase v9

App.js file:

import { db } from './firebase';

export default function App() {

  async function loadPhotos() {
    try {
      db.ref('users/photos')
        .then(url => {
          console.log('URL: ', url);
        })
        .catch(e => console.log(e));
      console.log('Got here');
    } catch (error) {
      console.log('error', error);
    }
  }
 ...............
}

firebase.js file:

import firebase from 'firebase/compat/app';
import { getDatabase } from 'firebase/database';

const firebaseConfig = {
  apiKey: '......',
  authDomain: '.....',
  projectId: '....',
  storageBucket: '....',
  messagingSenderId: '....',
  appId: '.....',
  measurementId: '....',
};

if (!firebase.apps.length) {
  firebase.initializeApp(firebaseConfig);
}
export const db = getDatabase();
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

In v9 and later of the Firebase SDK, most functionality that was a method on the objects in the past, is now available as a top-level function.

So instead of db.ref('users/photos'), you need to do ref(db, 'users/photos').

You're also missing a get call, which is how you actually retrieve the data from the reference:

get(ref(db, 'users/photos'))
  .then(url => {
    console.log('URL: ', url);
  })
  .catch(e => console.log(e));

This is all pretty well documented in the Firebase documentation on reading data, so I recommend keeping that handy. Alternatively you can use the compat paths in v9, to make the older syntax work as shown in the upgrade guide/

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