reusable mutation
#116
-
right now on the i.e type Payload = { id : string, name : string}
export const useAddName = (
mutationOpts?: UseMutationOptions<any, Payload>
) => {
const { $api } = useNuxtApp();
return useMutation({
...mutationOpts,
mutation: ({ id, name }: Payload) =>
$api(`/add/${id}`, {
body: { name },
method: "POST",
}),
});
}; but when we want to use the composable like this const { mutate, isLoading } = useAddName({
onSettled() {
refresh();
form.resetForm();
},
}); this will got an error because property
|
Beta Was this translation helpful? Give feedback.
Answered by
posva
Nov 20, 2024
Replies: 1 comment 3 replies
-
Omit the mutation from the type: type Payload = { id : string, name : string}
export const useAddName = (
mutationOpts?: Omit<UseMutationOptions<any, Payload>, 'mutation'>
) => {
const { $api } = useNuxtApp();
return useMutation({
...mutationOpts,
mutation: ({ id, name }: Payload) =>
$api(`/add/${id}`, {
body: { name },
method: "POST",
}),
});
}; |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
hi-reeve
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Omit the mutation from the type: