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: 한슬희 #1

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
81 changes: 81 additions & 0 deletions src/components/Comment.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/** @jsxImportSource @emotion/react */

import { css } from "@emotion/react";
import { ChangeEvent, FormEvent, useState } from "react";

interface IComment {
name: string;
summary: string;
}

function Comment() {
const [comment, setComment] = useState<IComment[]>([]);
Copy link
Contributor

Choose a reason for hiding this comment

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

댓글들이 저장되어 있는 상태라, 이름을 복수형으로 짓는 것이 좋지 않을까요?

const [messageState, setMessageState] = useState("댓글이 아직 없어요");
const [nameState, setNameState] = useState<string>("");
const [summaryState, setSummaryState] = useState<string>("");

function onSubmitForm(event: FormEvent<HTMLFormElement>) {
event?.preventDefault();
setComment((prev) => [...prev, { name: nameState, summary: summaryState }])
setMessageState("댓글들")
setNameState("")
setSummaryState("");
}

function onNameInput(event: ChangeEvent<HTMLInputElement>) {
setNameState(event.target.value)
}

function onSummaryInput(event: ChangeEvent<HTMLInputElement>) {
setSummaryState(event.target.value);
}

return (
<div>
<span css={text}>{messageState}</span>
<form css={inputWrapper} onSubmit={onSubmitForm}>
<input placeholder="닉네임" css={eachInput} value={nameState} onChange={onNameInput} />
<input placeholder="내용" css={eachInput} value={summaryState} onChange={onSummaryInput} />
<button css={buttonWrapper}>확인</button>
</form>
<div css={commentSort}>
{comment.map((todo: IComment) => (
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
{comment.map((todo: IComment) => (
{comment.map((todo) => (

여기서는 type을 따로 지정해주지 않으셔도 타입 추론이 되는데, 따로 지정해주신 이유가 있으실까요??

Copy link
Contributor

Choose a reason for hiding this comment

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

그리고 댓글들이 리스트 렌더링되는 것인데, todo라는 이름은 부적절한 거 같아요

<span><b>{todo.name}</b>: {todo.summary}</span>
))}</div>
</div>
);
}

export default Comment;

const text = css`
font-size: 1.1rem;
font-weight: 700;
`;
Comment on lines +51 to +54
Copy link
Member

@NohWookJin NohWookJin Jun 19, 2022

Choose a reason for hiding this comment

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

emotion 사용이 나중에 관리할 때 더 쉬울 것 같다는 생각이 들었어요.
다음 번에 저도 꼭 사용해보겠습니다..😳


const inputWrapper = css`
margin: 0.6rem 0;
`

const eachInput = css`
all: unset;
border-bottom: 1px solid black;
font-size: 0.9rem;
font-weight: 300;
margin-right: 1rem;
`;

const buttonWrapper = css`
all: unset;
font-size: 0.8rem;
font-weight: 800;
cursor: pointer;
`;

const commentSort = css`
display: flex;
flex-direction: column;
height: 9rem;
overflow-y: auto;
margin: 0.7rem 0;
`