MutationTrigger type #2711
-
Hello In our project we have multiple mutations, that are handled more or less the same way. Until now, we had a separate method for each mutation, something like this: const [updatePasswordCall] = useUpdatePasswordMutation();
const resetPassword = async (mailAccountId: string, newPassword: string) => {
showInfoNotification();
await updatePasswordCall({
customerNumber: customerIds.customerNumber,
accountNumber: customerIds.accountNumber,
mailId: mailAccountId,
data: { password: newPassword },
})
.unwrap()
.then(() => {
showSuccessNotification();
})
.catch((error) => {
showErrorNotification(error);
});
}; It is especially a problem when we use multiple mutations in the same file, we have to repeat the above code for each and every mutation. MutationTrigger<MutationDefinition<DataType, BaseQueryFn<string | FetchArgs, unknown, FetchBaseQueryError, {}, FetchBaseQueryMeta>, never, void, 'reducer-patch'>>; and that is ok I guess, but the types are being imported from Any suggestions on how to handle multiple mutation triggers the same way? Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
My first thought would be function handle(triggerResult: { unwrap(): Promise<any> }) {
return triggerResult
.unwrap()
.then(() => {
showSuccessNotification();
})
.catch((error) => {
showErrorNotification(error);
});
} to be used as await handle(updatePasswordCall({
customerNumber: customerIds.customerNumber,
accountNumber: customerIds.accountNumber,
mailId: mailAccountId,
data: { password: newPassword },
})) Generally: you don't need the exact trigger type. Just write a function with the partial type that actually interests you (in this case I want the object to have a |
Beta Was this translation helpful? Give feedback.
My first thought would be
to be used as
Generally: you don't need the exact trigger type. Just write a function with the partial type that actually interests you (in this case I want the object to have a
.unwrap
function that returns aPromise
.