react-async-hook
react-async-hook copied to clipboard
Let users cancel abortable functions
Adds a cancel function to the result of useAsyncAbortable()
const result = useAsyncAbortable(async (signal: AbortSignal) => {}, []);
result.cancel();
This aborts the AbortSignal that is passed into the executed function. This is very helpful for longer running queries where you want to give users the opportunity to cancel running requests.
It reuses the logic that is already in place to abort queries whenever a new async call is made.