T
TanStack•2y ago
afraid-scarlet

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
afraid-scarlet
afraid-scarletOP•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
quickest-silver
quickest-silver•12mo ago
@TkDodo 🔮 do you know if there is a way to bundle the satisfies MutationOptions<any, any, any, any> approach into a util?
mere-teal
mere-teal•12mo 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?