Last active
February 24, 2020 13:21
-
-
Save Dodsaren/daf6a4b9658584cc191e5b134049885d to your computer and use it in GitHub Desktop.
This file contains hidden or 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'; | |
| 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; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment