Skip to content

reusable mutation #116

Closed Answered by posva
hi-reeve asked this question in Questions
Nov 20, 2024 · 1 comments · 3 replies
Discussion options

You must be logged in to vote

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",
			}),
	});
};

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@hi-reeve
Comment options

@posva
Comment options

@hi-reeve
Comment options

Answer selected by hi-reeve
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #115 on November 20, 2024 13:48.