Skip to content

Commit

Permalink
perf(useAsyncEffect): move isAsyncGenerator outside the hook (alibaba…
Browse files Browse the repository at this point in the history
  • Loading branch information
bijinfeng authored May 16, 2023
1 parent b0a67b9 commit a80979e
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions packages/hooks/src/useAsyncEffect/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ import type { DependencyList } from 'react';
import { useEffect } from 'react';
import { isFunction } from '../utils';

function isAsyncGenerator(
val: AsyncGenerator<void, void, void> | Promise<void>,
): val is AsyncGenerator<void, void, void> {
return isFunction(val[Symbol.asyncIterator]);
}

function useAsyncEffect(
effect: () => AsyncGenerator<void, void, void> | Promise<void>,
deps?: DependencyList,
) {
function isAsyncGenerator(
val: AsyncGenerator<void, void, void> | Promise<void>,
): val is AsyncGenerator<void, void, void> {
return isFunction(val[Symbol.asyncIterator]);
}
useEffect(() => {
const e = effect();
let cancelled = false;
Expand Down

0 comments on commit a80979e

Please sign in to comment.