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

176
Views
¿Por qué no puedo pasar variables con mi función?

Tengo este código en mi aplicación nativa de reacción que usa firebase:

 let bestTutors = []; const getBestTutors = async () => { const snapshot = await getDoc(docRef); bestTutors = snapshot.data().list; } getBestTutors(); console.log(bestTutors);

Pero cuando lo ejecuto, solo la consola registra "Array[ ]", he intentado usar .then() y todo tipo de cosas que no tienen sentido para mí, no sé si hay una forma de usarlo sin la espera. o ¿Cómo puedo pasar los datos a la variable :( ?

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

0

función de llamada con espera. Como éste

 await getBestTutors()

about 4 years ago · Juan Pablo Isaza Report

0

mira mis comentarios

Tu código 1

 let bestTutors = []; const getBestTutors = async () => { const snapshot = await getDoc(docRef); bestTutors = snapshot.data().list; } getBestTutors(); // Asynchronous function console.log(bestTutors); // this is called before getBestTutors() returns the data. So console.log(bestTutors) return de default value: []

el nuevo codigo

 let bestTutors = []; const getBestTutors = async () => { const snapshot = await getDoc(docRef); bestTutors = snapshot.data().list; } await getBestTutors(); // Wait until getBestTutors() has finished and then Next. console.log(bestTutors);

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!