Created
December 12, 2019 11:05
-
-
Save reatexpk/aef4e2a2f95b7041aa53c1af299f234f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useEffect, useMemo, useState } from "react"; | |
export const useAbortSignal = () => { | |
const [abortController] = useState(new AbortController()); | |
const signal = useMemo(() => abortController.signal, [abortController.signal]); | |
useEffect( | |
() => () => { | |
abortController.abort(); | |
}, | |
[abortController] | |
); | |
return signal; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment