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 a996595
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions packages/components/hooks/useDebounce.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
import { debounce, DebounceSettings } from 'lodash-es';
import { debounce } from 'lodash-es';
import { useCallback, useEffect } from 'react';
import { usePersistFn } from './usePersistFn';

interface DebounceSettingsLeading extends DebounceSettings {
// https://tsdocs.dev/docs/lodash-es/4.17.21/interfaces/_internal_.DebounceSettingsLeading.html
interface DebounceSettingsLeading {
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 a996595

Please sign in to comment.