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

365
Visualizações
How to show loader during multiple api calls in a loop in React

I have two API's

First API returns list of items which I am iterating to get each item's detailed data.

Here's the code

  const [loader, setLoader] = useState(false);
 
  React.useEffect(() => {
    const fetchUsers = async() => {
      setLoader(true);
      const users = await getUsers();
      const promises = users.map(async (user) => {
          let userData = await getUsersDetailedData(user.userId);
          return userData
      });
      let finalUsers = await Promise.all(promises);
      setLoader(false);
    }
    fetchUsers();
  }, [])

I am updating loader state before the api call and after call but it is not working.

Loader state is updating these many times and loader is not displaying logs

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Try it in this way,

React.useEffect(() => {
  const fetchUsers = async() => {
    const users = await getUsers();
    const promises = users.map(async (user) => {
        let userData = await getUsersDetailedData(user.userId);
        return userData
    });
    let finalUsers = Promise.all(promises);
    return finalUsers;
  }
  setLoader(true);
  fetchUsers().then(res=>{
    setLoader(false);
  });
}, [])
about 4 years ago · Juan Pablo Isaza Relatório
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