forked from ohcnetwork/care_fe
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updates on comments, moving debounce and nested code to proper files
- Loading branch information
1 parent
87dbee1
commit e2abfa6
Showing
7 changed files
with
62 additions
and
50 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { useEffect, useRef } from "react"; | ||
|
||
export default function useDebounce( | ||
callback: (...args: string[]) => void, | ||
delay: number, | ||
) { | ||
const callbackRef = useRef(callback); | ||
useEffect(() => { | ||
callbackRef.current = callback; | ||
}, [callback]); | ||
|
||
const timeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null); | ||
const debouncedCallback = (...args: string[]) => { | ||
if (timeoutRef.current) { | ||
clearTimeout(timeoutRef.current); | ||
} | ||
timeoutRef.current = setTimeout(() => { | ||
callbackRef.current(...args); | ||
}, delay); | ||
}; | ||
return debouncedCallback; | ||
} |