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

184
Visualizações
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 à 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