I am creating a react native project where on the click of a button I want some data to be fetched from firebase and printed in the console..But instead I am getting undefined printed..what am i doing incorrectly? this is the function being called after the button is clicked:
function printTodos() {
console.log(loadFutureTodos()); //this is where I am getting undefined..but why?
}
this is the function which fetches data from firebase:
function loadFutureTodos() {
let allFutureTodos = [];
firestore()
.collection('todos')
.where('user', '==', auth().currentUser.uid)
.where('time', '==', futureTime)
.orderBy('priority', 'desc')
.get()
.then(snap => {
snap.docs.map(each => {
let eachdict = {
id: each.id,
taskName: each.get('taskName'),
taskDesc: each.get('taskDesc'),
};
allFutureTodos.push(eachdict);
});
console.log(allFutureTodos);//this works perfectly..all the todos in firebase get fetched
})
.finally(() => {
return allFutureTodos;
});
}