Skip to content

Commit

Permalink
fix: Fixed problem with useDisposePromiseBridge after resolve
Browse files Browse the repository at this point in the history
  • Loading branch information
piotar committed Jul 16, 2023
1 parent 8e5d219 commit 2696f3a
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/hooks/useDisposePromiseBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { ComposeAbortController } from '../utils/ComposeAbortController';
export function useDisposePromiseBridge(signals?: AbortSignal[]): AbortController {
const createController = useCallback(() => new ComposeAbortController(signals), [signals]);
const [controller, setController] = useState<AbortController>(createController);
const controllerRef = useRef(controller);
controllerRef.current = controller;
const createRef = useRef(createController);
createRef.current = createController;

Expand All @@ -15,13 +17,12 @@ export function useDisposePromiseBridge(signals?: AbortSignal[]): AbortControlle
}, [controller, createRef]);

useEffect(
() => () =>
setController((composeController) => {
composeController.abort(new TriggerComponentDestroyedException());
return createRef.current();
}),
() => () => {
controllerRef.current.abort(new TriggerComponentDestroyedException());
setController((controllerRef.current = createRef.current()));
},
[createRef.current],
);

return controller;
return controllerRef.current;
}

0 comments on commit 2696f3a

Please sign in to comment.