Created
April 13, 2019 09:25
-
-
Save ohansemmanuel/f384456a7589816254c8b8297dad26be 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
function TimerWithRefID() { | |
const setIntervalRef = useRef(); | |
useEffect(() => { | |
const intervalID = setInterval(() => { | |
// something to be done every 100ms | |
}, 100); | |
// this is where the interval ID is saved in the ref object | |
setIntervalRef.current = intervalID; | |
return () => { | |
clearInterval(setIntervalRef.current); | |
}; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment