Created
February 21, 2026 22:58
-
-
Save web-crab/3e445bafa7cce89ad4507fee42efbbb9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 { useEffect, useRef, useState } from 'react'; | |
| export function useAbort(init?: (controller: AbortController) => void) { | |
| const [aborter] = useState(() => new AbortController()); | |
| const initRef = useRef(); | |
| initRef.current = init; | |
| useEffect(() => { | |
| initRef.current?.(aborter); | |
| return () => aborter.abort(); | |
| }, [aborter]); | |
| return aborter; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment