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

157
Visualizações
Can't I put multiple data arguments in the react-query useMutation hook?

If you look at the guide, the useMutation Hook argument is structured like this.

const {
  data,
  error,
  isError,
  isIdle,
  isLoading,
  isPaused,
  isSuccess,
  mutate,
  mutateAsync,
  reset,
  status,
} = useMutation(mutationFn, {
  cacheTime,
  mutationKey,
  networkMode,
  onError,
  onMutate,
  onSettled,
  onSuccess,
  retry,
  retryDelay,
  useErrorBoundary,
  meta
})

The asynchronous axios function is structured like this:

async function setSupplierRegister(
  basic: Basic,
  operator: Operator,
  delivery: Delivery,
  bank: Bank
): Promise<void> {
  await axiosInstance.post("/register", {
    basic: basic,
    operator: operator,
    delivery: delivery,
    bank: bank,
  });
}

The asynchronous function requires 4 arguments, but only 1 data value can be retrieved in the useMutation Hook argument. Therefore, if you declare 4 arguments to useMutation , an error occurs.


export function useRegister(): UseMutateFunction<
    void,
    unknown,
    any,
    unknown
> {
  const { mutate } = useMutation(
// (basic: Basic, operator: Operator, delivery: Delivery, bank: Bank) => setSupplierRegister(basic, operator, delivery, bank), error 
    (data: any) => setSupplierRegister(data),
  );
  return mutate;
}

How should I handle it to declare 4 arguments in the useMutation function?

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You can add arguments in the array for example:

export function useRegister(): UseMutateFunction<
    void,
    unknown,
    any,
    unknown
> {
  const { mutate } = useMutation(
// (basic: Basic, operator: Operator, delivery: Delivery, bank: Bank) => setSupplierRegister(basic, operator, delivery, bank), error 
    ([basic: Basic, operator: Operator, delivery: Delivery, bank: Bank]) => setSupplierRegister(basic, operator, delivery, bank),
  );
  return mutate;
}

and than call mutate:

mutate([basic, operator, delivery, bank])

The second option is to use an object but you will need to refactor the setSupplierRegister function:

async function setSupplierRegister(data): Promise<void> {
  await axiosInstance.post("/register", {
    data
  });
}

you can leave useMutation as it is, and you call mutate like this:

mutate({ basic, operator, delivery, bank })

In my opinion, the second approach is much cleaner and readable.

about 4 years ago · Santiago Trujillo Relatório
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