Skip to content

Commit 825c9ba

Browse files
committed
implements MockAbortController
1 parent a978568 commit 825c9ba

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

packages/react-async/src/useAsync.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ export interface FetchOptions<T> extends AsyncOptions<T> {
3333
}
3434

3535
const noop = () => {}
36+
class MockAbortController implements AbortController {
37+
public abort = noop
38+
readonly signal = {} as AbortSignal
39+
}
3640

3741
function useAsync<T extends {}>(options: AsyncOptions<T>): AsyncState<T>
3842
function useAsync<T extends {}>(promiseFn: PromiseFn<T>, options?: AsyncOptions<T>): AsyncState<T>
@@ -54,9 +58,7 @@ function useAsync<T extends {}>(
5458
const lastArgs = useRef<any[] | undefined>(undefined)
5559
const lastOptions = useRef<AsyncOptions<T> | undefined>(undefined)
5660
const lastPromise = useRef<Promise<T> | undefined>(undefined)
57-
const abortController = useRef<AbortController>({
58-
abort: noop,
59-
} as any)
61+
const abortController = useRef<AbortController>(new MockAbortController())
6062

6163
const { devToolsDispatcher } = globalScope.__REACT_ASYNC__
6264
const { reducer, dispatcher = devToolsDispatcher } = options

0 commit comments

Comments
 (0)