Skip to content

Compatibility between Mutation and useMutation, queryClient.fetchQuery and useQuery. #9038

Answered by TkDodo
zacharyweidenbach asked this question in Q&A
Discussion options

You must be logged in to vote

To create idiomatic compatibility with useMutation, I am using the Mutation api to achieve this.

you’d want queryClient.getMutationCache().build(...):

build<TData, TError, TVariables, TContext>(
client: QueryClient,
options: MutationOptions<TData, TError, TVariables, TContext>,
state?: MutationState<TData, TError, TVariables, TContext>,
): Mutation<TData, TError, TVariables, TContext> {
const mutation = new Mutation({
mutationCache: this,
mutationId: ++this.#mutationId,
options: client.defaultMutationOptions(options),
state,
})
this.add(mutation)

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@zacharyweidenbach
Comment options

@TkDodo
Comment options

@zacharyweidenbach
Comment options

Answer selected by zacharyweidenbach
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants