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

99
Views
Not receiving the correct data from Promises?

I have a function that fetches data from an API, and the function works correctly as intended:

 const getStockData = async (stock) => {
try {
  const response = await axios.get(`${BASE_URL}${stock}${KEY_URL}`);
  console.log(response);
  return response;
} catch (error) {
  console.error('Error', error.message);
}

};

And I have another function that gets data from my firebase which then passes in the .ticker into the function above however when I log the response from the promise the data is returned null Is there a reason why its not working as intended?

const getMyStocks = async () => {
let promises = [];
let tempData = [];
const querySnapshot = await getDocs(collection(db, 'myStocks'));
querySnapshot.forEach((doc) => {
  console.log(doc.data().ticker);
  promises.push(
    getStockData(doc.data().ticker).then((res) => {
      console.log(res);
      tempData = {
        id: doc.id,
        data: doc.data(),
        info: res.data,
      };
    })
  );
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

getMyStocks must return the resolution of the promises it creates...

// to reduce nested promises, this takes an FB doc and adds the getStockData query to it
const getFBAndTickerData = async doc => {
  return getStockData(doc.data().ticker).then(res => {
    console.log(res);
    return {
      id: doc.id,
      data: doc.data(),
      info: res.data,
    };
  });
}

const getMyStocks = async () => {
  const querySnapshot = await getDocs(collection(db, 'myStocks'));
  let promises = querySnapshot.docs.map(doc => {
    console.log(doc.data().ticker);
    return getFBAndTickerData(doc);
  });
  return Promise.all(promises);
}
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!