Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reusable mutation #115

Closed
hi-reeve opened this issue Nov 20, 2024 · 0 comments
Closed

reusable mutation #115

hi-reeve opened this issue Nov 20, 2024 · 0 comments

Comments

@hi-reeve
Copy link

right now on the UseMutationOptions type property mutation are required.
the problem is when we wanted to create a reusable function that pass a mutation options

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 mutation is required

'UseMutationOptions<any, Payload, Error, _EmptyObject>'.
  Property 'mutation' is missing in type '{ onSettled(): void; }' but required in type 'UseMutationOptions<any, Payload, Error, _EmptyObject>'.
@github-project-automation github-project-automation bot moved this to 🆕 Triaging in Pinia Colada Roadmap Nov 20, 2024
Repository owner locked and limited conversation to collaborators Nov 20, 2024
@posva posva converted this issue into discussion #116 Nov 20, 2024
@github-project-automation github-project-automation bot moved this from 🆕 Triaging to Done in Pinia Colada Roadmap Nov 20, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
Archived in project
Development

No branches or pull requests

1 participant