TanStackT
TanStack3y ago
5 replies
dangerous-fuchsia

How do I create a resuable composable for a mutation?

Thanks for this great library.
I have a mutation that I want to reuse in multiple places, but I'm having trouble typing the
options
in the composable that I want to create e.g
export const useSaveUser = (options: MutationObserverOptions) => {
  return useMutation({
    mutationFn: saveUser,
    onSuccess: opts.onSuccess,
    onError: opts.onError,
  });
};

Can the mutations be re-used this way or is this something that is not intended?
Was this page helpful?