Skip to content

How to cancel/abort a mutation query? #1551

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

You must be logged in to vote

I don't think there is. The thing is: queries have no side-effect on the server, so you can run them as often as you want and also cancel them if you are no longer interested in the result. Per default, react-query will only ignore the result, but you can also attach a cancel method to the Promise to really abort the network request.

But as soon as you've fired off a mutation, once the backend has received it and has potentially started to update a database entry - how would you cancel that from the frontend... 🤷 .

Can you maybe elaborate on your use-case - what do you want to achieve?

Replies: 20 comments 35 replies

Comment options

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

Answer selected by Merott
Comment options

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

@kripod
Comment options

@kripod
Comment options

@TkDodo
Comment options

@kripod
Comment options

Comment options

You must be logged in to vote
2 replies
@p6l-richard
Comment options

@lynxtaa
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

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

@f0rr0
Comment options

@TkDodo
Comment options

@f0rr0
Comment options

Comment options

You must be logged in to vote
9 replies
@nathanhannig
Comment options

@jcready
Comment options

@TkDodo
Comment options

@jcready
Comment options

@TkDodo
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

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

@Estevete
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

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

Comment options

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

@TkDodo
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

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

@benjamintd
Comment options

@James-Whitfield
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

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

@derekbking
Comment options

@TkDodo
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

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

@zedrdave
Comment options

@TkDodo
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet