Skip to content
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

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@
2022년도 개발자들 FE - 리액트 03

> 6주차 과제 repo

## Result

![ezgif com-gif-maker (4)](https://user-images.githubusercontent.com/63100352/170821552-5fc38705-3830-4a3f-a53c-4e31a703bcbd.gif)
25,224 changes: 25,224 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"@emotion/react": "^11.9.0",
"@testing-library/jest-dom": "^5.14.1",
"@testing-library/react": "^13.0.0",
"@testing-library/user-event": "^13.2.1",
Expand Down
2 changes: 1 addition & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
-->
<title>React App</title>
</head>
<body>
<body style="margin: 0">
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
Expand Down
26 changes: 18 additions & 8 deletions src/App.tsx
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;
`;
21 changes: 21 additions & 0 deletions src/components/Clock.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
function Clock() {
const clock = document.querySelector<HTMLSpanElement>(".clock");
Copy link
Contributor

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


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
Copy link
Contributor

Choose a reason for hiding this comment

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

그냥 getMinutes, getSeconds를 사용하시지 않고, padStart를 사용하신 이유가 있을까요???

궁금해요 ~~~~ 👍 👍 👍

Copy link
Member Author

Choose a reason for hiding this comment

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

분이나 초가 한자릿수일 경우 앞에 0을 붙이기 위해 사용하였습니당

Copy link
Contributor

Choose a reason for hiding this comment

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

허걱 그런 이유가 ~~~~ 👍 👍 👍
여기에서 추가적으로 함수로 빼서 관리할 수도 있을 거 같네요 고럼!!! 👍 👍

Copy link
Member Author

Choose a reason for hiding this comment

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

허걱 고럼 좋겠네요 ~~~~


if (clock) {
clock.innerText = `${currentHour} : ${currentMinutes} : ${currentSecond}`;
}
setInterval(Clock);
Copy link
Contributor

Choose a reason for hiding this comment

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

이렇게 지정해주시면, 계속 실행되는 시간인 delay시간이 0으로 설정돼요!

https://developer.mozilla.org/en-US/docs/Web/API/setInterval#parameters


추가적으로 현재 인터벌을 통해 매번 컴포넌트를 다시 렌더링하고 있는데, 이런 패턴은 불필요한 실행까지 있을 수 있는 안티패턴으로 보여요!

인터벌을 이용해 setState하는 방향으로 수정해보시면 좋을 거 같아요~ 👍 👍 👍 👍 👍 👍

Copy link
Contributor

Choose a reason for hiding this comment

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

아 추가적으로 interval도 timeout처럼 clear하실 수 있으니 그런 방향으로 해보시면 좋을 거 같아요 ~!


return (
<>
<span className="clock">00 : 00 : 00</span>
</>
);
}

export default Clock;
37 changes: 37 additions & 0 deletions src/components/CountUp.tsx
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;
`;
32 changes: 32 additions & 0 deletions src/components/WaitMessage.tsx
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);
Copy link
Contributor

Choose a reason for hiding this comment

The 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;
`;
Loading