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

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

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 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