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

117
Vistas
How to cleanup a async call in react component useEffect after unmount?
  useEffect(() => {
    let isActive = true;
    //get user Data from session on start if loggedin.
    gameSessionService.get().then(allSessions=>{
      if (isActive){
        if(!allSessions.data.gameSessions) return;      
          allSessions.data.gameSessions.forEach((x,i)=>{
            sessionCards.push(<SessionCard key={i} nr={i} name={x.name} desc={x.description} id={x._id} owner={myUserData._id ===x.creator} />);
          })
          setGameSessions(sessionCards)
      }
    })
     return () => {
      isActive = false;
    }

}, [myUserData])

I am awaiting a async call on a http resource in my useEffect hook, and afterwards in return I just cleanup the gameSession varaible (which contains a DOM element that is rendered).

But I still get this error:

index.js:1 Warning: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in a useEffect cleanup function. at SessionCard (https://localhost:3000/static/js/main.chunk.js:2931:89) at section at div at MorphCard (https://localhost:3000/static/js/main.chunk.js:16875:46) at Account (https://localhost:3000/static/js/main.chunk.js:2040:85)

How do I cleanup a async function call in a propper way?

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