Last active
September 20, 2019 20:02
-
-
Save alexeyraspopov/1233af30f77e553fc7c949acf5f61dad 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
function useInterval(callback, delay) { | |
let handler = useRef(callback); | |
useEffect(() => { | |
handler.current = callback; | |
}, [callback]); | |
useEffect(() => { | |
let timer = setInterval(() => handler.current(), delay); | |
return () => clearInterval(timer); | |
}, [delay]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment