I have this:
export function useAddAnonymousUserMutation(
options?: UseMutationOptions<User>,
) {
return useMutation<User>({
...options,
mutationFn: () => addAnonymousUser(),
})
}
so that when I call useAddAnonUserMut() I can add { onSuccess: => (data) => {} } and data can be of type User.
Thats all great, but I am wondering if there is a better way to write this.
I tried both
export function useAddAnonymousUserMutation<TData extends User>(
options?: UseMutationOptions<TData>,
) {
return useMutation<TData>({
...options,
mutationFn: () => addAnonymousUser(),
})
}
and
export function useAddAnonymousUserMutation<TData = User>(
options?: UseMutationOptions<TData>,
) {
return useMutation<TData>({
...options,
mutationFn: () => addAnonymousUser(),
})
}
and I get type errors that TData could be overridden by something with other type contstraints.
How would you make this code better/DRYer?