Created
October 28, 2019 14:51
-
-
Save csenio/3cd991334ef2ee61d6a292ca8222b43a to your computer and use it in GitHub Desktop.
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
import {useState, useEffect} from 'react' | |
export default function useDebounce(value) { | |
const [debouncedValue, setDebouncedValue] = useState(value) | |
useEffect(() => { | |
const handler = setTimeout(() => { | |
setDebouncedValue(value) | |
}, 500) | |
return () => { | |
clearTimeout(handler) | |
} | |
}, [value]) | |
return debouncedValue | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment