garage-webui/src/hooks/useDebounce.ts
wenson af376beb5b refactor: update API endpoints and improve type safety across hooks
- Refactored `useDebounce` to enhance type safety with generic arguments.
- Updated `FetchOptions` in `api.ts` to use `unknown` instead of `any` for better type safety.
- Changed API endpoints in bucket-related hooks to use new versioned endpoints.
- Improved type definitions in bucket hooks and added specific types for mutation options.
- Enhanced `useConnectNode`, `useAssignNode`, and other cluster hooks to use new API endpoints and improved type safety.
- Updated health check and key management hooks to reflect new API structure.
- Refined utility functions and type definitions for better clarity and maintainability.
2025-07-15 15:59:47 +08:00

21 lines
471 B
TypeScript

import { useCallback, useRef } from "react";
export const useDebounce = <Args extends unknown[]>(
fn: (...args: Args) => void,
delay: number = 500
) => {
const timerRef = useRef<NodeJS.Timeout | null>(null);
const debouncedFn = useCallback(
(...args: Args) => {
if (timerRef.current) {
clearTimeout(timerRef.current);
}
timerRef.current = setTimeout(() => fn(...args), delay);
},
[fn, delay]
);
return debouncedFn;
};