useAbortController – A React Hook to work with the AbortController

Kent C. Dodds recently floated this snippet around, a React Hook to easily work with the the AbortController: function useAbortController() { const abortControllerRef = React.useRef() const getAbortController = React.useCallback(() => { if (!abortControllerRef.current) { abortControllerRef.current = new AbortController() } return abortControllerRef.current }, []) React.useEffect(() => { return () => getAbortController().abort() }, [getAbortController]) const getSignal = […]

JavaScript asyncawait: Resolving Promises in parallel

Recently I saw a colleague implement some functionality in which he required two results from an API using async–await. The piece of code looked something like this: The code looks fine, is syntactically correct, and works … but there’s one big problem with it: the calls are made sequentially. To run these calls – which […]

Cancel a JavaScript Promise with AbortController

👋 This post also got published on Medium. If you like it, please give it some love a clap over there. In How to Cancel Your Promise Seva Zaikov has done a nice writeup on several techniques on how to cancel promises. After also touching generators and async/await the conclusion is that you can’t actually […]