From 502b52e4f06633c5e3fba51af80ecee967dd0798 Mon Sep 17 00:00:00 2001 From: "Mr. Algorithm" <11aravipratapsingh@gmail.com> Date: Sat, 4 Oct 2025 19:49:40 +0530 Subject: [PATCH] Update hooks/useDebounce.ts Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- hooks/useDebounce.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/hooks/useDebounce.ts b/hooks/useDebounce.ts index 3a6b138..2ffbe2f 100644 --- a/hooks/useDebounce.ts +++ b/hooks/useDebounce.ts @@ -4,12 +4,16 @@ import { useCallback, useRef } from 'react'; export function useDebounce(callback: () => void, delay: number) { const timeoutRef = useRef(null); + const callbackRef = useRef(callback); + + // Keep callback ref up to date + callbackRef.current = callback; return useCallback(() => { - if(timeoutRef.current) { + if (timeoutRef.current) { clearTimeout(timeoutRef.current); } - timeoutRef.current = setTimeout(callback, delay); - }, [callback, delay]) + timeoutRef.current = setTimeout(() => callbackRef.current(), delay); + }, [delay]) } \ No newline at end of file