Using useMutation mutate params as mutationKeys

Is there a way to extract the params to use in the options?

const useQrCodePrintPostMutation = () => {
  const { enqueueSnackbar, closeSnackbar } = useSnackbar();

  return useMutation(
    ({ formData }: UseBaseDataPostMutation) => {
      return client(
        `printer?userId=${formData.userId}&wiId=${formData.wiId}&numberOfCopies=${formData.numberOfCopies}`
      );
    },
    {
      mutationKey: ['qrCode', 'printer', formData.someId], // <--- HERE
      onSuccess: async (data) => {
        enqueueSnackbar('Detaildaten wurden gespeichert.', {
          variant: 'success',
        });

        return data;
      },
      onError: (mutationError) => {
        displayErrorSnackbar({
          message: 'Druck Daten NIO.',
          error: mutationError,
          enqueueSnackbar,
          closeSnackbar,
        });
      },
    }
  );
};


Sadly I have to mutate from a map function - API excepts only per 'print' data...
Was this page helpful?