You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I just wanted to stop by to say I've been trying a new API, and I think use-async-effect could consider supporting the AbortController API. It seemed an opaque API for me before, but after experimenting a bit it seems like a very similar example to the useRef() API:
I am not sure how (if any) to use it, but I can see maybe providing it as a second parameter:
useAsyncEffect(async(isMounted,signal)=>{try{constres=awaitfetch(`/users/${id}`,{ signal });constdata=awaitres.json();if(!isMounted())return;setUser(data);}catch(error){console.error(error);}},[]);
On the other hand, I think these are bad:
Mixing try/catch with normal if checks for handling the lifecycle. It seems to be the way fetch() works, but it's very ugly.
Signal has an onabort callback, which is very similar to the second callback in use-async-effect. Again, two different ways of doing almost the same.
It can probably be done in user-land in a not-difficult way (going to attempt this soon). The main advantage of doing it this way is the availability of passing it straight into fetch(), which seems the most common case for use-async-effect.
The text was updated successfully, but these errors were encountered:
Hey, sorry for the very late reply! This sounds like a great idea, but I'm not sure if we should implement it into the library itself. Have you already done some experimentation with your own implementation?
Hi, it's me again :)
I just wanted to stop by to say I've been trying a new API, and I think
use-async-effect
could consider supporting the AbortController API. It seemed an opaque API for me before, but after experimenting a bit it seems like a very similar example to theuseRef()
API:I am not sure how (if any) to use it, but I can see maybe providing it as a second parameter:
On the other hand, I think these are bad:
try
/catch
with normalif
checks for handling the lifecycle. It seems to be the wayfetch()
works, but it's very ugly.onabort
callback, which is very similar to the second callback inuse-async-effect
. Again, two different ways of doing almost the same.fetch()
, which seems the most common case foruse-async-effect
.The text was updated successfully, but these errors were encountered: