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

384
Visualizações
How to read firestore data in react native?

Hello I am new to react native and particullary firebase. I've been watching tutorial about using firebase with react native and i read the react native firebase documentation but i am stuck. I have data in my firestore data base, in my collection called user but I am not able to read, to get the data from it. Here is my firestore database : Here is my firestore database

and here is how I tried to get the data in my component :

const Profile = ({navigation, ...props}) => {



    async function getUserData () {
        const userCollection = await await firebase.firestore().collection('users').doc(firebase.auth().currentUser.uid).get()
        return userCollection
    }
    console.log('🐲' + getUserData())

this return me that : [object Object]

I also tried this, (it was how it was done in the instagram clone tutorial of Adrian Twarog) :

const Profile = ({navigation, ...props}) => {

  function getUserDataFirstTry() {
        firebase.firestore()
        .collection("users")
        .doc(firebase.auth().currentUser.uid)
        .get()
        .then((snapchot) => {
            if(snapchot.exists){
                console.log('🦜' +  snapchot.data())
            } else {
                console.log('merde ca marche pas')
            }
        })
    }

    console.log('🐲🐲' + getUserDataFirstTry())

But I get the same result in my console : [object Object]

I tried to put my function in a useEffect hook but this changes nothing. Can you tell me what I am doing wrong ? (if possible in the second example because it's realtime changes). Thanks.

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

0

As Nicholas commented, since you're concatenating snapchot.data() to a string, you get the string representation of that object, which is pretty useless.

To log a specific field from the data:

console.log('🦜' +  snapchot.data().userName)

To log all fields from the data in a more useful format:

console.log('🦜' +  JSON.stringify(snapchot.data()))

Note: the proper spelling is snapshot (not snapchot), but I kept your original spelling here for ease of copy/paste.

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