Created
January 20, 2020 17:27
-
-
Save etienne-dldc/8007175783669198ee258415ca2759c2 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
const [start] = useState(Date.now()); | |
const [, setRandomNum] = useState(0); | |
const diff = Date.now() - start; | |
useEffect(() => { | |
const current = diff % 1000; | |
const time = 1000 - current; | |
const timer = setTimeout(() => { | |
setRandomNum(Math.random()); | |
}, time); | |
return () => { | |
clearTimeout(timer); | |
}; | |
}); | |
const num = 5 - Math.floor(diff / 1000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment