Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

174
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda