Add useDebounce hook for debouncing input values
Fix parsing
This commit is contained in:
parent
aa7f412f14
commit
56f66e9e8f
4 changed files with 92 additions and 20 deletions
19
src/utils/Debounce.jsx
Normal file
19
src/utils/Debounce.jsx
Normal file
|
@ -0,0 +1,19 @@
|
|||
import { useEffect, useState } from 'react'
|
||||
|
||||
function useDebounce(value, delay) {
|
||||
const [debouncedValue, setDebouncedValue] = useState(value)
|
||||
|
||||
useEffect(() => {
|
||||
const handler = setTimeout(() => {
|
||||
setDebouncedValue(value)
|
||||
}, delay)
|
||||
|
||||
return () => {
|
||||
clearTimeout(handler)
|
||||
}
|
||||
}, [value, delay])
|
||||
|
||||
return debouncedValue
|
||||
}
|
||||
|
||||
export default useDebounce
|
Loading…
Add table
Add a link
Reference in a new issue