Skip to content

Instantly share code, notes, and snippets.

@lucas-lm
Created March 1, 2020 14:16
Show Gist options
  • Save lucas-lm/3a49d7cacf1aca1fd824047f7b0b6d9f to your computer and use it in GitHub Desktop.
Save lucas-lm/3a49d7cacf1aca1fd824047f7b0b6d9f to your computer and use it in GitHub Desktop.
A little react hook for abort controller of fetch api
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