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

390
Vistas
Wait for API response before return function - ReactJS

I have a function getData() like this:

const getData = () => {
 const lsData = dummyJsonDataForTest;
 if (condition) {
  return lsData;
 }
 // call API here
 apiService
  .getData()
  .then((json) => {
    return json.data; 
  })
  .catch(() => {
    return null;
  })
 return null;
};

I want to return a response from the API call if the condition is false, but seems that the function getData() will return null before the API response.

Is there any way to make it wait for the response before the function return null?

Thank you in advance.

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