Skip to content

Conversation

@jyeon03
Copy link

@jyeon03 jyeon03 commented Jul 30, 2025

@jyeon03 jyeon03 requested a review from sayyyho July 30, 2025 10:42
@jyeon03 jyeon03 self-assigned this Jul 30, 2025
<h2>useSomething 실습</h2>
<p>{name}</p>
<button className="modern-btn" onClick={changeName}>
누구게

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

효과가 많아서 재미있는 것 같아요
이름이 뜬 후에는 버튼 이름을 누구게 말고 다른 걸로 바꾸면 좋을 것 같아요

setName((prev) => (prev === "아기사자" ? "아기사자 백지연" : "아기사자"));
};

useEffect(() => {
Copy link

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 실행 코드가 분리되어있어서 깔끔합니다

Copy link

@Soi-coding Soi-coding left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

과제 하시느라 수고하셨습니다!

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 === "아기사자" ? "아기사자 백지연" : "아기사자"));

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 === "아기사자" ? "아기사자 백지연" : "아기사자"));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prev를 활용해 최신 상태 기준으로 안전하게 업데이트하는 점 배워갑니다아

Comment on lines +8 to +9
const [name, setName] = useState("아기사자");
const { fire2 } = useConfetti();

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,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Math.random()을 넣어서 confetti가 화면 곳곳에서 터지는 효과가 다채롭고 재밌는 것 같아요!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.