-
Notifications
You must be signed in to change notification settings - Fork 0
Subin min #6
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?
Subin min #6
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,16 @@ | ||
| import { useSomething } from "../hooks/useSomething"; | ||
| import { useTextColor } from "../hooks/useTextColor"; | ||
|
|
||
| export const YourOwnHookPage = () => { | ||
| // const { something... } = useSomething(); | ||
| // 하단 UI에 자유롭게 위에서 받아온 값들을 바인딩 해보세요~ | ||
| const { color, changeColor } = useTextColor(); | ||
|
|
||
| return ( | ||
| <div> | ||
| <h2>useSomething 실습</h2> | ||
| <h2 style={{ color }}>useSomething 실습</h2> | ||
| <button className="modern-btn" onClick={changeColor}> | ||
| 색상 변경 | ||
| </button> | ||
| </div> | ||
| ); | ||
| }; | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,29 @@ | ||
| import { useState, useEffect } from "react"; | ||
| const calculateTimeLeft = (targetDate) => { | ||
| const difference = targetDate.getTime() - new Date().getTime(); | ||
|
|
||
| if (difference <= 0) { | ||
| return { days: 0, hours: 0, minutes: 0, seconds: 0 }; | ||
| } | ||
|
|
||
| const days = Math.floor(difference / (1000 * 60 * 60 * 24)); | ||
| const hours = Math.floor((difference / (1000 * 60 * 60)) % 24); | ||
| const minutes = Math.floor((difference / (1000 * 60)) % 60); | ||
| const seconds = Math.floor((difference / 1000) % 60); | ||
|
|
||
| return { days, hours, minutes, seconds }; | ||
| }; | ||
|
|
||
| export const useCountdown = (targetDate) => { | ||
| const [timeLeft, setTimeLeft] = useState(() => calculateTimeLeft(targetDate)); | ||
|
|
||
| useEffect(() => { | ||
| const timer = setInterval(() => { | ||
| setTimeLeft(calculateTimeLeft(targetDate)); | ||
| }, 1000); | ||
|
|
||
| return () => clearInterval(timer); | ||
| }, [targetDate]); | ||
|
|
||
| return timeLeft; | ||
| }; |
This file was deleted.
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 색상 배열의 개수에 맞게 Math.floor(Math.random() * colors.length) 라고 코드 잘 작성해주신 것 같아요! |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import { useState } from 'react'; | ||
|
|
||
| export const useTextColor = () => { | ||
| // 여러분의 use{Something}을 만들어주세요! | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 커스텀 훅의 목적이 분명해서 보기 좋아요! |
||
| // 정답은 없습니다. 커스텀훅의 필요성을 스스로 느껴보세요. | ||
| // 아이디어를 생각하고, 스스로 구현하다가 어려우면 손 들어주세요! | ||
| const [color, setColor] = useState('black'); | ||
|
|
||
| const changeColor = () => { | ||
| // 예시로 색상을 랜덤하게 바꾸거나, 정해진 목록에서 바꿀 수 있음 | ||
| const colors = ['red', 'blue', 'green', 'orange', 'purple']; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 정해진 배열에서 색깔이 랜덤으로 뽑히게 한 점이 인상깊어요! |
||
| const nextColor = colors[Math.floor(Math.random() * colors.length)]; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 목록에서의 선택과 랜덤 변경을 모두 가능하게 해 둔 점이 인상 깊어요! UI에서 랜덤 선택 버튼을 따로 만들어봐도 재밌을 것 같습니다 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 버튼 클릭할 때마다 텍스트 색이 달라지는 경험이 직관적이면서도 재밌는 것 같습니다!
Comment on lines
+7
to
+12
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. changeColor 시 기존 색상과 같은 값이 다시 나올 수 있는데 while 루프나 필터링으로 개선 가능할 것 같습니다 |
||
| setColor(nextColor); | ||
| }; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 정해진 목록뿐만이 아니라 랜덤으로 색상 변경하는 것까지 구현하셨네요!
Comment on lines
+10
to
+14
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. 랜덤으로 색을 고르도록 잘 구현하신 것 같아요.!! |
||
|
|
||
| return { color, changeColor }; | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,26 @@ | ||
| // 커스텀훅 코드를 작성해보세요! | ||
| import { useEffect, useState } from "react"; | ||
|
|
||
| export const useWindowSize = () => { | ||
| const [windowSize, setWindowSize] = useState({ | ||
| width: window.innerWidth, | ||
| height: window.innerHeight, | ||
| }); | ||
|
|
||
| useEffect(() => { | ||
| const handleResize = () => { | ||
| setWindowSize({ | ||
| width: window.innerWidth, | ||
| height: window.innerHeight, | ||
| }); | ||
| }; | ||
|
|
||
| window.addEventListener("resize", handleResize); | ||
|
|
||
| return () => { | ||
| window.removeEventListener("resize", handleResize); | ||
| }; | ||
| }, []); | ||
|
|
||
| return { windowSize }; | ||
| }; |
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.
간단하지만 아이디어가 좋은 것 같아요
필요 없는 주석은 삭제해도 좋을 것 같아요