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

180
Views
Is there an equivalent of a dependency array for useMutation?

I have a custom hook called useAxios. This is actually a wrapper for a useQuery hook that either returns the cached axios instance, or creates a new one by refreshing the JWT.

Now if I create a mutation that relies on this axios instance:

export function useExampleMutation() {
  const axios = useAxios();
  return useMutation((thing) => 
     axios.post(`/do-something-cool/${thing}`)
  )
}

Now, as far as I understand, when I use it, the mutate function is referentially stable:

export function ExampleComponent() {

  const exampleMutation = useExampleMutation();

  useEffect(() => {
    // ...
  }, [exampleMutation.mutate]) //
  //                  ^^^^^^ This is referentially stable 

  return <div>...</div>
}

So the useEffect hook won't be triggered with every render.

But I wouldn't want this to be the case if the token is refreshed and I get a brand new axios instance. So how would I specify that I should get a new instance whenever it does like if it were a regular callback:

export function useExampleCallback() {
  const axios = useAxios();
  return useCallback((thing) => 
     axios.post(`/do-something-cool/${thing}`), 
  [axios])
}
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!