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

143
Views
Returning a value from firestore snapshot

So I have this function:

export const getLastMsg = (user, convoid) => {
  let item = []
   user &&  db.collection('chats').doc(convoid).collection('messages').orderBy('date', 'desc').limit(1).onSnapshot(snap=> {
    let items = []
    snap.forEach(doc => items.push(doc.data())) 
    item = items[0]
  }) 
}

When I call this function in my app, i get undefined, but when i console log the value inside the snapshot i get the value. Any Idea how I can make this function return the value?

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

0

You are not returning item in getLastMsg() - it's always going to return undefined.

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!