T
TanStack4y ago
fair-rose

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,
});
},
}
);
};
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...
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?