-
Notifications
You must be signed in to change notification settings - Fork 0
[김연비] 커스텀 훅 실습 #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
잘 만든 것 같아요
useSomething 말고 다른 파일명으로 바꾸면 좋을 것 같아요
필요 없는 주석도 삭제하면 좋을 것 같습니다
| const g = Math.floor(Math.random() * 256); | ||
| const b = Math.floor(Math.random() * 256); | ||
| setBgColor(`rgb(${r}, ${g}, ${b})`); | ||
| console.log(bgColor); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
배경색 신박하네요! 콘솔 로그는 삭제하는 것이 더 깔끔할 것 같아요!
| const changeColor = () => { | ||
| const r = Math.floor(Math.random() * 256); | ||
| const g = Math.floor(Math.random() * 256); | ||
| const b = Math.floor(Math.random() * 256); | ||
| setBgColor(`rgb(${r}, ${g}, ${b})`); | ||
| console.log(bgColor); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
랜덤 배경색을 직접 훅으로 분리한 게 신선합니닷!
useEffect로 console를 옮겨보는 것 도 좋을 것 같습니다
| const g = Math.floor(Math.random() * 256); | ||
| const b = Math.floor(Math.random() * 256); | ||
| setBgColor(`rgb(${r}, ${g}, ${b})`); | ||
| console.log(bgColor); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
랜덤 컬러를 생성하는 게 재밌네요.
useRandomColor와 같이 직관적인 이름을 사용해도 좋을 것 같네요!
| const changeColor = () => { | ||
| const r = Math.floor(Math.random() * 256); | ||
| const g = Math.floor(Math.random() * 256); | ||
| const b = Math.floor(Math.random() * 256); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Math.random()을 256으로 곱하고 Math.floor()로 반올림해서 RGB 범위를 정확히 맞춘 점이 좋은 거 같아요 !
Soi-coding
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
과제하시느라 수고하셨어요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
r, g, b 숫자를 랜덤하게 뽑아서 배경색을 바꾸는 아이디어가 좋은 것 같아요!
| bgColor: "", | ||
| }); | ||
|
|
||
| const changeColor = () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
기본 r,g,b 색상을 정의한 후 랜덤 색상을 출력 가능하게 구현한 점이 깔끔하고 인상 깊습니다!
| const r = Math.floor(Math.random() * 256); | ||
| const g = Math.floor(Math.random() * 256); | ||
| const b = Math.floor(Math.random() * 256); | ||
| setBgColor(`rgb(${r}, ${g}, ${b})`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RGB 값을 랜덤으로 생성하는 로직이 직관적이고 이해하기 쉽게 작성된 것 같아요!
| const changeColor = () => { | ||
| const r = Math.floor(Math.random() * 256); | ||
| const g = Math.floor(Math.random() * 256); | ||
| const b = Math.floor(Math.random() * 256); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Math.random()과 rgb() 문자열 조합으로 동작이 명확하고 재미있는 것 같습니다
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
만든 커스텀훅과 맞게 파일명을 바꾸면 코드이해에 더 쉬울 것 같아요!
[Refactor: useWindowSize로 리팩토링]
1번 실습 내용을 해결하였으나, 수정사항이 있어 3번에서 한 번 더 수정하였습니다.
[Refactor: useCountdown으로 리팩토링]
2번 실습 내용을 해결하였으나, 수정사항이 있어 3번에서 한 번 더 수정하였습니다.
[Feature: useSetColor 구현]
배경색 바꾸기 버튼을 누르면 배경색이 랜덤으로 바뀝니다.