Skip to content
This repository was archived by the owner on Sep 19, 2021. It is now read-only.

[2주차] 정시원 미션 제출합니다#1

Open
sebastianrcnt wants to merge 5 commits into
CEOS-Developers:masterfrom
sebastianrcnt:master
Open

[2주차] 정시원 미션 제출합니다#1
sebastianrcnt wants to merge 5 commits into
CEOS-Developers:masterfrom
sebastianrcnt:master

Conversation

@sebastianrcnt

Copy link
Copy Markdown

이번 미션은 지난주 미션보다 난이도가 좀 있었고, 뭘 잘못 건드렸는지 중간에 갑자기 오류가 나서 고치려고 한참을 삽질하다가 결국 해결을 못해서 clone 하고 처음부터 다시 만들긴 했지만 오류 해결을 해보려는 과정에서 의도치 않게 npm과 패키지를 다루는 방법에 대해서 찾아보고 더 공부해보게 되었습니다..... 또한 컴포넌트 스타일링을 할 때 어떻게 하면 반복되는 부분을 정리하고 깔끔하게 코드를 짤 수 있을지를 계속 고민해보고 연습해야 할 것 같습니다. 그리고 Git 에 익숙하지 않아 프로젝트를 할 때 체계적으로 코딩할 단위를 나눠서 하는 것이 아직은 서툰 것 같다고 느꼈습니다.

https://react-todo-11th.sebastianrcnt.now.sh/

@greatSumini
greatSumini self-requested a review April 11, 2020 06:00
@greatSumini greatSumini added the mission 귀염뽀짝 미션제출 label Apr 11, 2020

@greatSumini greatSumini left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

고생 많으셨습니다~~
TodoItem 컴포넌트에 React.memo 정말 잘 적용해주셨네요!
TodoList에도 적용해보시면 좋을 것 같습니다 ㅎㅎ
개발자도구에서 style을 복사하는 것보단 직접 작성하시는 연습 해주시면 좋습니다 ㅠㅠ
스타일링에 대한 이해도가 높으면 좋은 컴포넌트 구조를 짜는데 도움이 된답니다.
styled-component 적용 안 된 부분이 많네요!
component의 가독성을 높이기 위해서 return문에선 정말 필수적인 jsx 구조와, prop들만 남겨놓는게 좋아요!
style 같은 부가요소들은 밑쪽에 styled-component로 작성해서 치워놓구요 ㅎ
고생많으셨습니다! 리뷰 확인 및 반영 부탁드릴게요~~

모범 답안도 참고해주세요! 감사합니다 😊
모범답안 링크

Comment thread components/todo-input.js
Comment on lines +5 to +6
const [thisTodo, setThisTodo] = useState({
})

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
const [thisTodo, setThisTodo] = useState({
})
const [form, setForm] = useState({})
  1. thisTodo는 현재 입력중인 todo라는 역할을 잘 설명하지 못 하는 것 같아요!
  2. 빈 객체라서 줄바꿈 하지 않아도 될 것 같습니닿

Comment thread components/todo-input.js
const [thisTodo, setThisTodo] = useState({
})

const inputChangeHandler = (el) => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

  1. 함수 이름을 지을때 동사가 맨 앞에 오도록 해주세요!
  2. el이 무엇의 약자인가요..?
Suggested change
const inputChangeHandler = (el) => {
const handleInputChange = (event) => {

Comment thread components/todo-input.js
})

const inputChangeHandler = (el) => {
const { name, value } = el.target;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

destructuring 잘 써주셨네요 👍

Comment thread components/todo-input.js
Comment on lines +11 to +21
if (name === 'dueDate') {
if (value.length > 8) {
el.target.value = value.slice(0, 8);
return;
}
}

setThisTodo({
...thisTodo,
[name]: value
})

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
if (name === 'dueDate') {
if (value.length > 8) {
el.target.value = value.slice(0, 8);
return;
}
}
setThisTodo({
...thisTodo,
[name]: value
})
setThisTodo({
...thisTodo,
[name]: name === 'dueDate' ? value.slice(0, 8) : value
})

이렇게 리팩토링할 수 있습니다!
slice(0, 8)는 현재 value의 length가 8 미만이면 그냥 안 자르고 그대로 반환하기 때문에 추가로 조건문을 작성할 필요가 없어용

Comment thread components/todo-input.js
Comment on lines +26 to +28
<TimeInput>
<p style={{"fontSize":"1.5rem","padding":"0px","margin":"0px"}}>시간</p>
<input style={{ "width": "80%", "borderWidth": "1px", "borderStyle": "solid", "borderColor": "rgb(97, 97, 97)", "borderImage": "initial", "padding": "0.5rem 0.8rem" }} name="dueDate" onChange={inputChangeHandler} type="number" placeholder="날짜를 입력하세요 (ex.20200404)"></input>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

styled-componet를 사용해주세요 ㅎ ㅠ

Comment thread components/todo-item.js
Comment on lines +30 to +34
const areEqual = (prevProps, nextProps) => {
return prevProps.id === nextProps.id;
}

export default React.memo(TodoItem, areEqual); No newline at end of file

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

잘 적용해주셨네요!!! 좋습니다 ㅎ 👍

Comment thread components/todo-list.js
<TodoItem />
</Wrapper>
);
export default function TodoList({ todos, completeTodo }) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

TodoList에도 React.memo를 적용해보세요~

Comment thread components/todo-list.js
return (
<Wrapper>
{todos.sort((todo1, todo2) => {
return todo1.dueDate < todo2.dueDate ? -1 : todo1.dueDate > todo2.dueDate ? 1 : 0;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

sort의 compare 함수는 양수, 0, 음수여부만 판단하기 때문에

Suggested change
return todo1.dueDate < todo2.dueDate ? -1 : todo1.dueDate > todo2.dueDate ? 1 : 0;
return todo1.dueDate - todo2.dueDate;

라고만 해주셔도 됩니다 ㅎ

Comment thread components/todo-list.js
<Wrapper>
{todos.sort((todo1, todo2) => {
return todo1.dueDate < todo2.dueDate ? -1 : todo1.dueDate > todo2.dueDate ? 1 : 0;
}).map((todo) => (todo.isComplete ? null : <TodoItem key={todo.id} {...todo} completeTodo={completeTodo} />))}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

map함수에서 3항연산자를 사용해 선택적으로 return 하는 것 보다 filter함수를 쓰는게 더 좋을 것 같아요!

Comment thread pages/index.js
setCounter(counter + 1);
setTodos([
...todos,
{ id: counter, content, dueDate, isComplete: false }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

isComplete 사용하신 것 참신하네요 👍

@puba5 puba5 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

전체적으로 너무 멋진 코드였던 것 같아요. 추억이 담긴 미션이네요 ^^

Comment thread pages/index.js
}

// check whether dueDate is valid
const dateRegExp = /^\d{8}$/;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

정규표현식을 사용해주신 점이 정말 멋있는 것 같아요

Comment thread pages/index.js
<div style={{flex:0.3}}></div>
<TodoList completeTodo={completeTodo} todos={todos} />
</Contents>
<div style={{position:'fixed', right:0, top:0, padding: '1px', fontSize:'9px', backgroundColor:'grey'}}>CEOS 11기 정시원</div>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

style을 inline으로 다는 것은 별로 좋은 습관은 아니랍니다 ㅎㅎ

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

Labels

mission 귀염뽀짝 미션제출

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants