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

222
Visualizações
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 Respostas
Responde à pergunta

0

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

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