MobxMutation
Class wrapper for @tanstack-query/core mutations with MobX reactivity
Usage
Create an instance of MobxMutation
with mutationFn
parameter
ts
const mutation = new MobxMutation({
queryClient,
abortSignal, // Helps you to automatically clean up mutation
mutationFn: async ({ signal, queryKey }) => {
const response = await petsApi.createPet({ name: 'Fluffy' }, { signal });
return response.data;
},
});
Features
method mutate(variables, options?)
Runs the mutation. (Works the as mutate
function in useMutation
hook)
hook onDone()
Subscribe when mutation has been successfully finished
hook onError()
Subscribe when mutation has been finished with failure
method reset()
Reset current mutation
property result
Observable mutation result (The same as returns the useMutation
hook)