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

220
Views
Obtenga los datos de un usuario en firestore y muéstrelos en Expo

Estoy usando Expo y Firebase para crear una aplicación. Actualmente estoy usando este código para obtener la información del perfil del usuario:

 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) } }

De esta manera, funciona. Se muestra la alerta. Sin embargo, estoy tratando de mostrar el valor de esta manera

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

Esto es lo que he probado:

  • devolviendo la variable y luego llamando a la función
  • usando ``const [fullName, setFullName] = useState(''), y configurando "fullName". Aquí está ese código:
 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();

Después de agregar la línea "const [fullName, setFullName] = useState('')", el código de repente no funciona. Al probarlo en el navegador web, la página está en blanco.

Ninguno de estos ha funcionado. Definitivamente, los datos se reciben correctamente, pero la parte de visualización no funciona.

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

0

Encontré la solución: había olvidado importar useState, lo hice y funcionó.

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!