Introduction to abortable async functions for React with hooks

added by JavaScript Kicks
12/12/2018 9:34:51 AM

542 Views

While useAsyncTask is sufficient to create an async task, it's not trivial to write a func with the rule that it needs to handle AbortController. Hence, we provide two helper hooks that wrap useAsyncTask. const task1 = useAsyncTaskTimeout(func, delay);const task2 = useAsyncTaskFetch(url); useAsyncTaskTimeout is just to wait a certain amount of time and then run func.


0 comments