swr icon indicating copy to clipboard operation
swr copied to clipboard

Cancelation

Open shuding opened this issue 2 years ago • 2 comments

⚠️ 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.

shuding avatar Apr 17 '22 15:04 shuding

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.

700software avatar Jul 07 '22 22:07 700software

Looks good! Maybe add a new configurarion option for People who don't want it?

l-mbert avatar Aug 13 '22 21:08 l-mbert

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.

CaptainPants avatar Dec 18 '22 11:12 CaptainPants