React · Senior · Question 38 of 75

How do you properly support request cancellation in TanStack Query?

Explanation

queryFn: ({ signal }) => fetch(url, { signal }). The library cancels the request if the component unmounts before the response, the key changes, or cancelQueries is called. Without passing signal, only result handling is cancelled while the HTTP request itself continues.

Further reading

Problem with a question

React · Senior · question 38

Test yourself

Take the React · Senior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz