-
Notifications
You must be signed in to change notification settings - Fork 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
assignment-07: 한슬희 #3
base: main
Are you sure you want to change the base?
Changes from all commits
3d8326e
13fc08c
4799a1b
4a2f474
1368179
1d182fc
feeab8b
bc162b2
8801337
ec9bac9
9dfe162
2145e70
8ac781b
cfcd0ac
5cea60d
28fda2e
82f1679
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,25 @@ | ||
import CommentSection from "./components/CommentSection"; | ||
import Introduce from "./components/Introduce"; | ||
/** @jsxImportSource @emotion/react */ | ||
import { css } from "@emotion/react"; | ||
import Clock from "./components/Clock"; | ||
import CountUp from "./components/CountUp"; | ||
import WaitMessage from "./components/WaitMessage"; | ||
|
||
function App() { | ||
return ( | ||
<main> | ||
<h1>안녕하세요! 저는 오혜성이에여</h1> | ||
|
||
<Introduce /> | ||
<CommentSection /> | ||
</main> | ||
<section css={sortItem}> | ||
<CountUp /> | ||
<WaitMessage /> | ||
<Clock /> | ||
</section> | ||
); | ||
} | ||
|
||
export default App; | ||
|
||
const sortItem = css` | ||
display: flex; | ||
flex-direction: column; | ||
padding: 30px; | ||
font-size: 22px; | ||
font-weight: 700; | ||
`; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
function Clock() { | ||
const clock = document.querySelector<HTMLSpanElement>(".clock"); | ||
|
||
const currentTime = new Date(); | ||
const currentHour = currentTime.getHours(); | ||
const currentMinutes = String(currentTime.getMinutes()).padStart(2, "0"); | ||
const currentSecond = String(currentTime.getSeconds()).padStart(2, "0"); | ||
Comment on lines
+6
to
+7
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. 분이나 초가 한자릿수일 경우 앞에 0을 붙이기 위해 사용하였습니당 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. 허걱 고럼 좋겠네요 ~~~~ |
||
|
||
if (clock) { | ||
clock.innerText = `${currentHour} : ${currentMinutes} : ${currentSecond}`; | ||
} | ||
setInterval(Clock); | ||
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. 이렇게 지정해주시면, 계속 실행되는 시간인 https://developer.mozilla.org/en-US/docs/Web/API/setInterval#parameters 추가적으로 현재 인터벌을 통해 매번 컴포넌트를 다시 렌더링하고 있는데, 이런 패턴은 불필요한 실행까지 있을 수 있는 안티패턴으로 보여요! 인터벌을 이용해 setState하는 방향으로 수정해보시면 좋을 거 같아요~ 👍 👍 👍 👍 👍 👍 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. 아 추가적으로 interval도 |
||
|
||
return ( | ||
<> | ||
<span className="clock">00 : 00 : 00</span> | ||
</> | ||
); | ||
} | ||
|
||
export default Clock; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/** @jsxImportSource @emotion/react */ | ||
import { css } from "@emotion/react"; | ||
import { useState } from "react"; | ||
|
||
function Count() { | ||
const [count, setCount] = useState<number>(0); | ||
function CountUp() { | ||
setCount((prev) => prev + 1); | ||
} | ||
return ( | ||
<div css={sortItem}> | ||
<span>{count}</span> | ||
<button css={increaseButton} onClick={CountUp}> | ||
더하기 | ||
</button> | ||
</div> | ||
); | ||
} | ||
|
||
export default Count; | ||
|
||
const sortItem = css` | ||
display: flex; | ||
flex-direction: column; | ||
`; | ||
|
||
const increaseButton = css` | ||
all: unset; | ||
width: fit-content; | ||
height: fit-content; | ||
padding: 10px 14px; | ||
border-radius: 5px; | ||
background-color: #e84393; | ||
font-weight: 400; | ||
font-size: 13px; | ||
cursor: pointer; | ||
`; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** @jsxImportSource @emotion/react */ | ||
import { css } from "@emotion/react"; | ||
import { useEffect, useState } from "react"; | ||
|
||
function WaitMessage() { | ||
const [textState, setTextState] = useState<string>("잠시만 기다려주세요!!"); | ||
|
||
useEffect(() => { | ||
const timeout = setTimeout(() => setTextState("거의 다 됐어요!"), 3000); | ||
return () => clearTimeout(timeout); | ||
}, []); | ||
|
||
useEffect(() => { | ||
const timeout = setTimeout( | ||
() => setTextState("정보가 확인됐어요 :D"), | ||
8000 | ||
); | ||
return () => clearTimeout(timeout); | ||
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 ( | ||
<div css={itemWrapper}> | ||
<span>{textState}</span> | ||
</div> | ||
); | ||
} | ||
|
||
export default WaitMessage; | ||
|
||
const itemWrapper = css` | ||
margin: 20px 0; | ||
`; |
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.
리액트에서
쿼리 셀렉터
를 사용하는 것은 지양하시는 것이 좋아요!그 대신
ref
에 대해 공부해보시면 좋을 거 같아요 ~~~! 👍 👍https://ko.reactjs.org/docs/hooks-reference.html#useref