Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

283
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda