Skip to content

Commit

Permalink
chore: fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
liweijie0812 committed Mar 2, 2025
1 parent 2172420 commit fbb3171
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions packages/components/hooks/useDebounce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,24 @@ import { debounce, DebounceSettings } from 'lodash-es';
import { useCallback, useEffect } from 'react';
import { usePersistFn } from './usePersistFn';

// https://tsdocs.dev/docs/lodash-es/4.17.21/interfaces/_internal_.DebounceSettingsLeading.html
interface DebounceSettingsLeading extends DebounceSettings {
leading: true;
maxWait?: number;
trailing?: boolean;
}

const useDebounce = <T extends (...args: any) => any>(func: T, delay: number, options?: DebounceSettingsLeading) => {
// https://tsdocs.dev/docs/lodash-es/4.17.21/interfaces/_internal_.DebouncedFuncLeading.html
interface DebouncedFuncLeading<T extends (...args: unknown[]) => unknown> {
cancel(): void;
flush(): ReturnType<T>;
(...args): ReturnType<T>;
(...args): ReturnType<T>;
}
const useDebounce = <T extends (...args: unknown[]) => unknown>(
func: T,
delay: number,
options?: DebounceSettingsLeading,
): DebouncedFuncLeading<T> => {
const callback = usePersistFn(func);

// eslint-disable-next-line react-hooks/exhaustive-deps
Expand Down

0 comments on commit fbb3171

Please sign in to comment.