Skip to content

Commit

Permalink
refactor: adjust the handling of cancel operations
Browse files Browse the repository at this point in the history
  • Loading branch information
atzcl committed Dec 22, 2020
1 parent f030e2d commit 7f7b68e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
7 changes: 4 additions & 3 deletions packages/hooks/src/useDebounceEffect/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useEffect, EffectCallback, DependencyList, useState } from 'react';
import { DebounceOptions } from '../useDebounce/debounceOptions';
import useDebounceFn from '../useDebounceFn';
import useUpdateEffect from '../useUpdateEffect';
import useUnmount from '../useUnmount';

function useDebounceEffect(
effect: EffectCallback,
Expand All @@ -15,11 +16,11 @@ function useDebounceEffect(
}, options);

useEffect(() => {
run();

return cancel;
return run();
}, deps);

useUnmount(cancel);

useUpdateEffect(effect, [flag]);
}

Expand Down
7 changes: 4 additions & 3 deletions packages/hooks/src/useThrottleEffect/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useEffect, EffectCallback, DependencyList, useState } from 'react';
import { ThrottleOptions } from '../useThrottle/throttleOptions';
import useThrottleFn from '../useThrottleFn';
import useUpdateEffect from '../useUpdateEffect';
import useUnmount from '../useUnmount';

function useThrottleEffect(
effect: EffectCallback,
Expand All @@ -15,11 +16,11 @@ function useThrottleEffect(
}, options);

useEffect(() => {
run();

return cancel;
return run();
}, deps);

useUnmount(cancel);

useUpdateEffect(effect, [flag]);
}

Expand Down

0 comments on commit 7f7b68e

Please sign in to comment.