Skip to content

Instantly share code, notes, and snippets.

@thinkawitch
thinkawitch / abort-controller.js
Last active July 6, 2022 14:18 — forked from kentcdodds/abort-controller.js
React hook for AbortController with reset
function useAbortController(runEffect=false, runLayoutEffect=false) {
const acRef = useRef()
const getAbortController = useCallback(() => {
if (!acRef.current) {
acRef.current = new AbortController()
}
return acRef.current
}, []);
if (runEffect) {