Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

170
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!