-
Notifications
You must be signed in to change notification settings - Fork 0
[백지연] 커스텀 훅 실습 #1
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
| <h2>useSomething 실습</h2> | ||
| <p>{name}</p> | ||
| <button className="modern-btn" onClick={changeName}> | ||
| 누구게 |
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.
효과가 많아서 재미있는 것 같아요
이름이 뜬 후에는 버튼 이름을 누구게 말고 다른 걸로 바꾸면 좋을 것 같아요
| setName((prev) => (prev === "아기사자" ? "아기사자 백지연" : "아기사자")); | ||
| }; | ||
|
|
||
| useEffect(() => { |
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.
name 값이 바뀔 때마다 useEffect로 confetti가 실행되게 해둔 점이 좋네용!! 그리고 name변경과 confetti 실행 코드가 분리되어있어서 깔끔합니다
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.
단순히 name만 바뀌는 게 아니라 fire2()라는 효과도 같이 줘서 좋은 것 같아요!
| const { fire2 } = useConfetti(); | ||
|
|
||
| const changeName = () => { | ||
| setName((prev) => (prev === "아기사자" ? "아기사자 백지연" : "아기사자")); |
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.
상태 업데이트를 prev 기반으로 처리해서 최신 상태를 안전하게 반영시킨 점이 인상 깊습니다!
| const { fire2 } = useConfetti(); | ||
|
|
||
| const changeName = () => { | ||
| setName((prev) => (prev === "아기사자" ? "아기사자 백지연" : "아기사자")); |
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.
prev를 활용해 최신 상태 기준으로 안전하게 업데이트하는 점 배워갑니다아
| const [name, setName] = useState("아기사자"); | ||
| const { fire2 } = useConfetti(); |
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.
이름 상태를 관리하면서 변경될 때마다 useConfetti의 fire2 효과를 실행하는 좋은 코드인 것 같습니다
| spread: 360, | ||
| origin: { | ||
| x: Math.random(), | ||
| y: Math.random() - 0.2, |
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()을 넣어서 confetti가 화면 곳곳에서 터지는 효과가 다채롭고 재밌는 것 같아요!
커스텀 훅 세션
구현 내용
Refactor: useWindowSize로 리팩토링
Refactor: useCountdown, calculateTime으로 리팩토링
Feature: useMyName 구현