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

226
Views
Get one user's data in firestore and display in Expo

I am using Expo and Firebase to create an app. I am currently using this code to get the user's profile information:

async function getUserInfo(){
    try {
      let doc = await firestore
        .collection('users')
        .doc(auth.currentUser.uid)
        .get();

      if (!doc.exists){
        alert('No user data found!')
      } else {
        let dataObj = doc.data();
        alert(dataObj.FullName);
      }
    } catch (err){
    alert('There is an error.', err.message)
    }
  }

This way, it works. The alert is displayed. However, I am trying to display the value like this

   <Text>Name: {here_some_variable_for_name}</Text>

Here's what I have tried:

  • returning the variable and then calling the function
  • using ``const [fullName, setFullName] = useState(''), and setting "fullName". Here is that code:
  const [fullName, setFullName] = useState('')

  async function getUserInfo(){
    try {
      let doc = await firestore
        .collection('users')
        .doc(auth.currentUser.uid)
        .get();

      if (!doc.exists){
        alert('No user data found!')
      } else {
        let dataObj = doc.data();
        setFullName(dataObj.FullName);
      }
    } catch (err){
    alert('There is an error.', err.message)
    }
  }

  getUserInfo();


After adding the line "const [fullName, setFullName] = useState('')", the code suddenly doesn't work. When testing it in the web browser, the page is just blank.

Neither of these have worked. The data is definitely being received correctly, but the displaying part is not working.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Found the solution: I had forgotten to import useState, I did that and it worked.

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!