import { useRef, useEffect, useCallback } from 'react';
/**
 * Custom hook to manage an AbortController instance.
 * @returns A memoized callback that returns the current `AbortController` instance, creating a new one if necessary.
 */
export default () => {
    const abortControllerRef = useRef(null);
    useEffect(() => () => {
        // Safe to abort again, even it's already aborted.
        abortControllerRef.current?.abort();
    }, []);
    return useCallback(() => {
        // If there is no controller, or it has been aborted, create a new one.
        if (!abortControllerRef.current || abortControllerRef.current.signal.aborted) {
            abortControllerRef.current = new AbortController();
        }
        // TypeScript expects non-null, so we assert here
        return abortControllerRef.current;
    }, []);
};
//# sourceMappingURL=useAbortController.js.map