Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

217
Vistas
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 Respuestas
Responde la pregunta

0

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

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda