{ "$schema": "https://ui.shadcn.com/schema/registry-item.json", "name": "use-debounce-fun", "description": "A custom hook that debounces a function.", "files": [ { "path": "src/registry/new-york/hooks/use-debounce-fun.ts", "content": "import { useCallback, useRef } from \"react\";\n\n/**\n * A custom hook that debounces a function.\n * @param func The function to debounce.\n * @param delay The debounce delay in milliseconds.\n * @returns A debounced version of the function.\n */\n\nexport function useDebounceFun void>(\n func: T,\n delay: number,\n): T {\n const timerRef = useRef(null);\n\n const debouncedFunc = useCallback(\n (...args: Parameters) => {\n if (timerRef.current) {\n clearTimeout(timerRef.current);\n }\n timerRef.current = setTimeout(() => {\n func(...args);\n }, delay);\n },\n [func, delay],\n );\n\n return debouncedFunc as T;\n}\n", "type": "registry:hook" } ], "type": "registry:hook" }