Mutate data outside from react component/hook · TanStack/query · Discussion #6743 · GitHub
Skip to content
Discussion options

You must be logged in to vote

you mean fire off a mutation ? There isn't much gain in doing that outside of react. You can't take advantage of the lifecycle management, so you can just as easily fire off a request with just fetch / axios.

But it's definitely possible:

export const executeMutation = <TVariables>(
queryClient: QueryClient,
options: MutationOptions<any, any, TVariables, any>,
variables: TVariables,
) => {
return queryClient
.getMutationCache()
.build(queryClient, options)
.execute(variables)
}

Replies: 5 comments 4 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by TkDodo
Comment options

You must be logged in to vote
1 reply
@denisborovikov
Comment options

Comment options

You must be logged in to vote
1 reply
@RBilly
Comment options

Comment options

You must be logged in to vote
2 replies
@TkDodo
Comment options

@romellem
Comment options

This comment was marked as spam.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
7 participants