mirror of
https://github.com/khairul169/garage-webui.git
synced 2025-10-14 14:59:32 +07:00

- 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.
21 lines
471 B
TypeScript
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;
|
|
};
|