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

168
Views
How to get return value of a Promise<Array[]> from an Async-Await Function?

Im trying to get the return value of an async-await function but im not getting the value i need.

const filterStuff = async (filters) => {
   //some code here
   await client<StuffPagination>(endpoint,body)
   .then((stuffresult)=>{
      const {stuff,page} = stuffresult;
      let fiteredStuff as Stuff[] = stuff;
      console.log(filteredStuff);
      return filteredStuff;
   })
   .catch(()=>{
      //do something
   })
   .finally(()=>{
      //do something
   });
};

How do i get the actual return value Stuff[] of the async-await function outside of the function? I have tried using .then to get the data but log for the data is always undefined while the console.log(filteredStuff) that im returning has a value. Is there something im missing?

  useEffect(() => {
    filterStuff(BaseFilters).then((data) => {
      console.log(data);
    });
  }, []);
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You are not returning at required place. Please see below updated code which await for the response.

const filterStuff = async (filters) => {
   try {
      //some code here
      const stuffresult = await client<StuffPagination>(endpoint,body);
      const {stuff,page} = stuffresult;
      let fiteredStuff as Stuff[] = stuff;
      console.log(filteredStuff);
      return filteredStuff;
   }
   catch {
      //do something
   }
   finally {
      //do something
   }
};
about 4 years ago · Juan Pablo Isaza Report

0

you are missing a return statement in you filterStuff function

const filterStuff = async (filters) => {
   //some code here
   return client<StuffPagination>(endpoint,body)
   .then((stuffresult)=>{
      const {stuff,page} = stuffresult;
      let fiteredStuff as Stuff[] = stuff;
      console.log(filteredStuff);
      return filteredStuff;
   })
   .catch(()=>{
      //do something
   })
   .finally(()=>{
      //do something
   });
};

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!