Open
Conversation
Member
import {useRef, useEffect} from "react";
export default function TimerDisplay({time}){
const timeRef = useRef(null);
useEffect(()=>{
const timeText = `${String(Math.floor(time / 60)).padStart(2, '0')} : ${String(Math.floor(time%60)).padStart(2, '0')}`;
if(timeRef.current)
timeRef.current.textContent = timeText;
}, [time]);
return (
<>
<h1>🍅뽀모도로 타이머🍅</h1>
<h2 ref={timeRef}>00 : 00</h2>
</>
);
}해당 코드는 과제 요구사항 때문에 억지로 useEffect와 useRef를 사용한 느낌입니다. export default function TimerDisplay({ time }) {
const minutes = String(Math.floor(time / 60)).padStart(2, '0');
const seconds = String(time % 60).padStart(2, '0');
return (
<>
<h1>🍅뽀모도로 타이머🍅</h1>
<h2>{minutes} : {seconds}</h2>
</>
);
}요구사항 때문에 어쩔 수 없었던 건 알지만, 실제로 코드를 짜실 때는 해당 방식으로 사용하시길 권장드립니다. |
Member
|
이건 절대적인 정답은 아니고 제 개인적 의견입니다만, 아래와 같은 코드는 유지보수와 협업 측면에서 좋지 않다고 느껴집니다. setMods(!mods);
mods?setTime(1500):setTime(300);먼저 mod를 반전시키고 그에 따라 삼항연산자로 setTime 값을 다르게 주입시키는데, 코드를 읽는 입장에서 헷갈립니다. mods ? setTime(300) : setTime(1500);
setMods(!mods);(물론 제 말이 정말 절대적인 참은 아닙니다! 그냥 코드를 읽다가 불편해서 드리는 의견이에요!) |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
뽀모도로 타이머를 만들어봤습니다!!