mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
18 lines
380 B
JavaScript
18 lines
380 B
JavaScript
|
import { useEffect, useState } from 'react'
|
||
|
|
||
|
export default function useDebounce(value, delay = 0) {
|
||
|
const [debouncedValue, setDebouncedValue] = useState(value)
|
||
|
|
||
|
useEffect(() => {
|
||
|
const timer = window.setTimeout(() => {
|
||
|
setDebouncedValue(value)
|
||
|
}, delay)
|
||
|
|
||
|
return () => {
|
||
|
window.clearTimeout(timer)
|
||
|
}
|
||
|
}, [value, delay])
|
||
|
|
||
|
return debouncedValue
|
||
|
}
|