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

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