overleaf/services/web/frontend/js/shared/hooks/use-abort-controller.js
Alf Eaton 2328dd1705 Add useAbortController hook (#4234)
GitOrigin-RevId: 731f86a2b07cd2c3189e6ca86bba9fbbc913f429
2021-06-24 02:06:45 +00:00

14 lines
301 B
JavaScript

import 'abort-controller/polyfill'
import { useEffect, useState } from 'react'
export default function useAbortController() {
const [controller] = useState(() => new AbortController())
useEffect(() => {
return () => {
controller.abort()
}
}, [controller])
return controller
}