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

109
Views
how can a function return data after the promise is resolved in javascript?

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;
      });
  }
about 4 years ago · Juan Pablo Isaza
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!