swr
swr copied to clipboard
Cancelation
⚠️ This proposal isn't finalized yet.
An abort signal will always be passed to fetcher
via the option:
useSWR('/api', (url, { signal }) => {
return fetch(url, { signal }).then(res => res.json())
})
And SWR will abort the signal when the request is discarded and the result is no longer needed. After aborted, SWR ignores the AbortError
thrown.
This is amazing! Elegant and in spirit with SWR's simplicity.
It would cause aborts to happen in applications where none were happening before. But is it a breaking change? I think not.
Looks good! Maybe add a new configurarion option for People who don't want it?
I have given implementation of this a go in the above PR if anyone is competent to have a look and give any feedback? Cheers.