Hello! I am trying to abort a POST request for example.
I have a modal that performs an API call, IF in the meantime I close the modal I want the API request to get canceled, anyone knows how to achieve that?
1 Reply
harsh-harlequin•2y ago
Your query function receives a signal. Pass that to the fetch function (or however you call your API)
Details here:
https://tanstack.com/query/v4/docs/framework/react/guides/query-cancellation
Query Cancellation | TanStack Query Docs
TanStack Query provides each query function with an AbortSignal instance, if it's available in your runtime environment. When a query becomes out-of-date or inactive, this signal will become aborted. This means that all queries are cancellable, and you can respond to the cancellation inside your query function if desired. The best part about th...