T
TanStack•2y ago
passive-yellow

mutationOptions helper

Hi there! I've been working on refactoring some of my codebase's react-query usage (with inspiration from https://tkdodo.eu/blog/the-query-options-api). I see there is a queryOptions helper, which can be used to build QueryOptions objects, and I've gotten through refactoring all of my queries. Is there such a thing for useMutation? Even though my function is returning a type that satisfies UseMutationOptions, typescript seems to not like it. Any suggestions? Thanks
No description
No description
4 Replies
passive-yellow
passive-yellowOP•2y ago
I guess I should be using setMutationDefaults?(https://tanstack.com/query/latest/docs/framework/react/guides/mutations#persist-mutations) Edit: maybe not... seems like this is more for offline use
optimistic-gold
optimistic-gold•2y ago
You can use satisfies
sensitive-blue
sensitive-blue•15mo ago
@TkDodo 🔮 do you know if there is a way to bundle the satisfies MutationOptions<any, any, any, any> approach into a util?
rival-black
rival-black•15mo ago
function mutationOptions<TData = unknown, TError = DefaultError, TVariables = void, TContext = unknown>(
options: MutationOptions<TData, TError, TVariables, TContext>,
) {
return options;
}
function mutationOptions<TData = unknown, TError = DefaultError, TVariables = void, TContext = unknown>(
options: MutationOptions<TData, TError, TVariables, TContext>,
) {
return options;
}

Did you find this page helpful?