DEV Community

Discussion on: React Query vs useSWR

Collapse
 
sakethkowtha profile image
sakethk

SWR will not cancel processing tasks while react-query will do that on these aspect react-query is bit ahead.

Collapse
 
brense profile image
Rense Bakker

From React Query documentation:

By default, queries that unmount or become unused before their promises are resolved are not cancelled.

Both React Query and SWR work with providing your own fetcher. Cancelling requests depends on what fetcher you use...

// Example abort with fetch:
const controller = new AbortController()
fetch('https://google.com', { signal: controller.signal }))
controller.abort()

// Example abort with axios
const source = axios.CancelToken.source()
axios.get('https://google.com', { cancelToken: source.token })
source.cancel()
Enter fullscreen mode Exit fullscreen mode