Created
March 1, 2020 14:16
-
-
Save lucas-lm/3a49d7cacf1aca1fd824047f7b0b6d9f to your computer and use it in GitHub Desktop.
A little react hook for abort controller of fetch api
This file contains 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 { useRef } from 'react' | |
function useAbortController() { | |
const abortControllerRef = useRef({}) | |
if (arguments.length === 0) abortControllerRef.current = new AbortController() | |
else { | |
for (let arg of arguments) { | |
abortControllerRef.current[arg] = new AbortController() | |
} | |
} | |
return abortControllerRef.current | |
} | |
export default useAbortController |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment