Skip to content

Commit a80979e

Browse files
authored
perf(useAsyncEffect): move isAsyncGenerator outside the hook (#2186)
1 parent b0a67b9 commit a80979e

File tree

1 file changed

+6
-5
lines changed
  • packages/hooks/src/useAsyncEffect

1 file changed

+6
-5
lines changed

packages/hooks/src/useAsyncEffect/index.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@ import type { DependencyList } from 'react';
22
import { useEffect } from 'react';
33
import { isFunction } from '../utils';
44

5+
function isAsyncGenerator(
6+
val: AsyncGenerator<void, void, void> | Promise<void>,
7+
): val is AsyncGenerator<void, void, void> {
8+
return isFunction(val[Symbol.asyncIterator]);
9+
}
10+
511
function useAsyncEffect(
612
effect: () => AsyncGenerator<void, void, void> | Promise<void>,
713
deps?: DependencyList,
814
) {
9-
function isAsyncGenerator(
10-
val: AsyncGenerator<void, void, void> | Promise<void>,
11-
): val is AsyncGenerator<void, void, void> {
12-
return isFunction(val[Symbol.asyncIterator]);
13-
}
1415
useEffect(() => {
1516
const e = effect();
1617
let cancelled = false;

0 commit comments

Comments
 (0)