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?
You are not returning item in getLastMsg() - it's always going to return undefined.