We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 3041130 commit c89efa4Copy full SHA for c89efa4
2024 Prep/machine_coding/react/src/hooks/useDebounce.ts
@@ -1,7 +1,7 @@
1
import { useState, useEffect } from 'react'
2
3
-const useDebounce = <T>(callBack: T, delay = 500) => {
4
- const [debouncedText, setDebouncedText] = useState<string>('')
+const useDebounce = (value: string, delay = 500) => {
+ const [debouncedText, setDebouncedText] = useState<string>(value)
5
6
useEffect(() => {
7
// * add delay for setting the valye
@@ -12,5 +12,7 @@ const useDebounce = <T>(callBack: T, delay = 500) => {
12
// * run clearTimeout in a cleanup function
13
return () => clearTimeout(timeOut)
14
}, [debouncedText, delay])
15
+
16
+ return debouncedText
17
}
18
export { useDebounce }
0 commit comments