Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

382
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
ยฉ 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!