Lots of changes
This commit is contained in:
parent
7b9f81dd64
commit
c66526241c
16 changed files with 286 additions and 114 deletions
14
src/hooks/useDebounce.jsx
Normal file
14
src/hooks/useDebounce.jsx
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
import { useState, useEffect } from "react"
|
||||
|
||||
export default function useDebounce(value, delay = 500) {
|
||||
const [debouncedValue, setDebouncedValue] = useState(value)
|
||||
|
||||
useEffect(() => {
|
||||
const timeout = setTimeout(() => {
|
||||
setDebouncedValue(value)
|
||||
}, delay)
|
||||
return () => clearTimeout(timeout)
|
||||
}, [value, delay])
|
||||
|
||||
return debouncedValue
|
||||
}
|
||||
Reference in a new issue