Skip to content

Instantly share code, notes, and snippets.

@hymm
Created April 4, 2020 16:43
Show Gist options
  • Select an option

  • Save hymm/65b6850fb83d30af5c04779e0a6e2c6a to your computer and use it in GitHub Desktop.

Select an option

Save hymm/65b6850fb83d30af5c04779e0a6e2c6a to your computer and use it in GitHub Desktop.
function useAbortController() {
const ref = useRef();
useEffect(() => () => ref.current.abort(), []);
return useCallback(() => {
ref.current = new AbortController();
return ref.current.signal;
}, []);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment