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

276
Visualizações
How can I pull all values from a Firestore document in React Native?

This is my database and the data I want to pull:

This is my code:

const MatchScreen = ({route}) => {

  const id = route.params.id;
  const booking = getDoc(doc(db, 'bookings', id))
  console.log(booking)

  return (
    <View style = {{justifyContent: 'center', alignItems: 'center'}}>
      <Text>{id}</Text>
  </View>
  )
      }

I got the id value from another page and that one is displayed properly on the screen, but when I try to console log booking to see if the values are there, this is what I get:

Promise {
  "_U": 0,
  "_V": 0,
  "_W": null,
  "_X": null,
}

What am I doing wrong?

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

0

When you call getDoc you get back a Future<DocumentSnapshot>. So to get the value from that, you have to use then() or await to resolve the Future and then call data() to get the document data.

const booking = getDoc(doc(db, 'bookings', id))
booking.then((doc) => {
  console.log(doc.data());
});

This is quite well covered in the documentation on getting a document, so I recommend spending some time there.

about 4 years ago · Juan Pablo Isaza Relatório

0

Getting a document from Firestore's Collection is an asynchronous operation and it is required to run the side effects code inside useEffecthook.

const MatchScreen = ({ route }) => {
  const [booking, setBooking] = useState(null);
  const bookingId = route.params.id;

  function getBooking(bookingId) {
    getDoc(doc(db, "bookings", bookingId)).then((snapshot) => {
      if (snapshots.exists) {
        booking = snapshots.data();

        setBooking(booking);
      }
    });
  }

  useEffect(() => {
    getBooking();
  }, []);

  console.log(" Booking :", booking);

  return (
    <View style={{ justifyContent: "center", alignItems: "center" }}>
      <Text>{bookingId}</Text>
    </View>
  );
};```


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