Best way to handle cancelling a multi-step mutation #4671
-
I appreciate there are other questions which look similar, but I'm refactoring a codebase which uses useEffect for a lot of its mutation logic, and I'd like to move to the simpler useMutation. Simply put, my question is this: If a mutation requires more than one asynchronous step, is there any way of cancelling that function if the component gets unmounted half way through its operation. In useEffect land, you can declare an |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
you cannot cancel mutations because mutations have side-effects on the server that cannot be stopped. For example, what would happen if you have a mutation that sends an email, and you would "cancel" the network request. How would you stop the email from being sent on the server? Or the database entry from being created? If you have one mutation that fires multiple requests and you want to perform checks in between each one and only call them conditionally, you should be able to do that. But once a mutation request has been sent, it cannot be cancelled. |
Beta Was this translation helpful? Give feedback.
you cannot cancel mutations because mutations have side-effects on the server that cannot be stopped. For example, what would happen if you have a mutation that sends an email, and you would "cancel" the network request. How would you stop the email from being sent on the server? Or the database entry from being created?
If you have one mutation that fires multiple requests and you want to perform checks in between each one and only call them conditionally, you should be able to do that. But once a mutation request has been sent, it cannot be cancelled.