Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

389
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda