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

167
Visualizações
How to read data from Firebase Real Time database with React Native?

I have a really simple problem, that when I try to read data from the FireBase database, with the following code I get this error: "TypeError: ref is not a function" . I dig trough a lot of documentation and they all use it like this, but I do not have a function like that for my ref variable. I want to query all the animal names for a user ('AllatNev').

import { getDatabase, ref, set } from 'firebase/database';

const db = getDatabase();
const user_ref = ref(db, auth.currentUser.uid); //This returns my db and the userID
const query = user_ref.child("AllatNev")        //This fails with "no child function"
console.log(query)

I can easily write data with this code:

  const reference = ref(db, auth.currentUser.uid +"/"+allatid);
  set(reference, {
    'AllatNev': AllatNev,
    'AllatFaj': valueFaj,
    'AllatFajta': AllatFajta,
    'AllatSzin': AllatSzin,
    'AllatNem': valueNem,
    'AllatSzul': dateText
  });

My data looks like this:

{
  "Gkmo3hhjNaZJ8yzjHcLKAyA3Op12" : {
    "allatid1041301e703d1" : {
      "AllatFaj" : "macska",
      "AllatFajta" : "Egyiptomi",
      "AllatNem" : "szuka",
      "AllatNev" : "Zolika",
      "AllatSzin" : "Fekete",
      "AllatSzul" : "2020-4-18"
    },
    "allatid53ba6d927a183" : {
      "AllatFaj" : "kutya",
      "AllatFajta" : "Border Collie",
      "AllatNem" : "kan",
      "AllatNev" : "Grafit",
      "AllatSzin" : "Kék",
      "AllatSzul" : "2016-4-18"
    }
  }
}
about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

This code can't work as you're using v8 syntax:

const query = user_ref.child("AllatNev")

Since you're using SDK version 9 or later, you should also use the syntax for that version to get the child node:

const query = child(user_ref, "AllatNev")

I always keep the list of v9 database functions handy when working on code like this, as it's the fastest way to find syntax problems like this.

about 4 years ago · Santiago Trujillo 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