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

155
Views
Conjunto de Firebase 9 de onSnapshot

Entonces necesito convertir datos de la instantánea de Firebase 9 a una matriz.
Se me ocurrió algo como esto, pero no devuelve nada.
Revisa los comentarios en mi código.
Supongo que debería usar promesas, pero no puedo encontrar la manera correcta.

 const fetchNewMessages = async (threadId: string, latestTimestamp: any) => { const q = query(threadRef(threadId), orderBy('timestamp', 'asc'), startAfter(latestTimestamp)); const messages: IMessage[] = []; onSnapshot(q, (querySnapshot) => { const docs = querySnapshot.docChanges(); docs.forEach((change) => { if (change.type === "added") messages.push(fetchDoc(change.doc)); }); console.log(messages.length); // here I get 34 }); console.log(messages.length); // here I get 0 return messages.reverse(); };
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

intente esperar "onSnapshot"

 const fetchNewMessages = (threadId: string, latestTimestamp: any) => { const q = query(threadRef(threadId), orderBy('timestamp', 'asc'), startAfter(latestTimestamp)); const messages: IMessage[] = []; return new Promise((resolve) => { onSnapshot(q, (querySnapshot) => { const docs = querySnapshot.docChanges(); docs.forEach((change) => { if (change.type === "added") messages.push(fetchDoc(change.doc)); }); resolve(messages.reverse()); }); }); };
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!