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

182
Vistas
How to prevent useEffect infinite loop when checking Apollo response for changes?

I'm calling a mutation like so:

const [deleteTask, deleteTaskResponse] = useMutation(deleteTaskMutation);

// this is called in a different component (all of this logic is in a context provider)
const deleteTaskFunction = (taskId) => {
  deleteTask({variables: { taskId }})
}

I have a a useEffect set up to monitor for when the deleteTaskResponse is changed to update state with the response like so:

useEffect(()=>{
   const { data, loading, error } = deleteTaskResponse;
   
   if (data && data.deleteTask){
       console.log(data.deleteTask)
       setTasks(data.deleteTask.tasks) // state
   }

}, [deleteTaskResponse])

I don't understand why this is causing an infinite effect loop as the response shouldn't be changing since the function is only called once. I've tried putting a console.log in the deleteTaskFunction and can confirm that it is only being called once when the delete button is pressed.

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