04월 19일 수요일
아기사자 스터디 STOPWATCH 만들기
시간 변수 설정하는게 가장 어려웠다
const hour = Math.floor(time / (3600 * 100)); const min = Math.floor((time % 360000) / 6000); const sec = Math.floor((time % 6000) / 100); const msec = time % 100;
그리고 시간을 0:00:00:00 단위로 표현하는 것에서 애를 좀 먹었다..
{hour}:{min.toString().padStart(2, "0")}: {sec.toString().padStart(2, "0")}:{msec.toString().padStart(2, "0")}
git 주소 : https://github.com/PPisland/Stopwatch
useEffect(() => {
if (isLoading) {
let interverId = setInterval(() => {
setTime(time + 1);
}, 10);
return () => {
clearInterval(interverId);
};
}
}, [time, isLoading]);