Conversation
greatSumini
left a comment
There was a problem hiding this comment.
ㅋㅋㅋ 오늘의 삽질은 최신문법의 소중함을 깨닫는 좋은 기회라고 생각해주셨으면 좋겠습니다.
고생하셨습니다! 리뷰 반영 후 커밋해주세요~
| @@ -1,32 +1 @@ | |||
| # react-todo | |||
src/components/todo/Todo.js
Outdated
| import TodoInput from './TodoInput'; | ||
| import TodoCard from './TodoCard'; | ||
|
|
||
| const Div = styled.div` |
There was a problem hiding this comment.
이 Component의 의도와 역할을 더 잘 설명할 수 잇는 네이밍이 좋을 것 같아요.
ex) Wrapper, Container, ...
src/components/todo/Todo.js
Outdated
| if (this.state.todoList.length === 0) { | ||
| return "표시할 TODO가 없어요!"; | ||
| } | ||
| else { |
There was a problem hiding this comment.
위의 if문에서 true로 걸렸다면 이미 return 됐을테니까, 여기서 else라고 써줄 필요가 없습니다!
|
|
||
| getTodo = () => { | ||
| if (this.state.todoList.length === 0) { | ||
| return "표시할 TODO가 없어요!"; |
There was a problem hiding this comment.
오늘 배운 조건부 렌더링을 활용해 리팩토링 해보는건 어떨까요? 참고할만한 글의 논리 && 연산자가 있는 인라인 조건을 참고해주세요!
There was a problem hiding this comment.
리팩토링 시도해봤는데 리턴에 계속 밑줄이 그어지면서 오류라고 뜨네요ㅜㅜ
There was a problem hiding this comment.
앗 완전히 구조를 바꿔야해요! ㅎㅎ.. 작성스타일 차이로 볼 수도 있는 부분이라고 생각해서 꼭 고치진 않으셔도 됩니당
src/components/todo/Todo.js
Outdated
| } | ||
| else { | ||
| let showTodoList = []; | ||
| for (let index = 0; index < this.state.todoList.length; index++) { |
There was a problem hiding this comment.
map함수를 사용해 리팩토링 해봐도 좋을 것 같아욯ㅎ
There was a problem hiding this comment.
map함수 syntax를 익혀보도록 하겠습니다! 아직 안 익숙하다보니 계속 익숙한 방식만 쓰게되네요 😅
src/components/todo/Todo.js
Outdated
| let newTodoList = Array.from(this.state.todoList); | ||
| newTodoList.push(_todo); | ||
| this.setState({ | ||
| todoList: newTodoList |
There was a problem hiding this comment.
| todoList: newTodoList | |
| todoList: [...this.state.todoList, _todo] |
spread operator를 이용해 깔끔하게 리팩토링할 수 있습니다~
src/components/todo/TodoCard.js
Outdated
| import React, { Component } from 'react'; | ||
| import styled from 'styled-components'; | ||
|
|
||
| const Div = styled.div` |
There was a problem hiding this comment.
이것 역시 더 좋은 네이밍을 찾을 수 있을 것 같아요! div는 아무것도 나타내지 못하거든요 :)
src/components/todo/TodoInput.js
Outdated
| render() { | ||
| return <div>화이팅^^</div>; | ||
| return ( | ||
| <form name="addListForm" |
There was a problem hiding this comment.
기본 제공되는 tag를 사용하지 않도록 리팩토링 해보세요!
There was a problem hiding this comment.
넵 기본 제공 태그를 지양하도록 하겠습니다
src/components/todo/Todo.js
Outdated
| } | ||
|
|
||
| onClick = (index) => { | ||
| console.log(this.state.todoList) |
There was a problem hiding this comment.
제가 추가한 코드네요 😂
이런 테스팅용 코드는 PR시에 모두 제거해주셔야합니다!
There was a problem hiding this comment.
다 지웠다고 생각했는데 남아있었군요..! 확인했습니다
greatSumini
left a comment
There was a problem hiding this comment.
고생하셨습니다! 추가 리뷰 해드렸으니 참고해주세요~
src/components/todo/Todo.js
Outdated
| return showTodoList; | ||
| } | ||
|
|
||
| let showTodoList = this.state.todoList.map((_todo, index) => { |
There was a problem hiding this comment.
- 추가적인 수정사항이 없으므로 let보다는 const가 적합해보이네요
- map함수의 결과를 그대로 return 해주셔도 됩니당
| newTodoList.push(_todo); | ||
| this.setState({ | ||
| todoList: newTodoList | ||
| todoList: [...this.state.todoList,_todo] |
src/components/todo/Todo.js
Outdated
| console.log(this.state.todoList) | ||
| let newTodoList = Array.from(this.state.todoList) | ||
| newTodoList.splice(index, 1); | ||
| this.setState({ todoList: newTodoList }); |
|
수정 완료했습니다~! |
greatSumini
left a comment
There was a problem hiding this comment.
고생하셨습니다 ㅎㅎ 점점 코드 질이 좋아지는게 눈에 보여서 제가 다 뿌듯하네요 👍
리뷰 반영 후 커밋부탁드립니다~
src/components/todo/TodoInput.js
Outdated
| return <div>화이팅^^</div>; | ||
| return ( | ||
| <Form name="addListForm" | ||
| onSubmit={(e) => { |
src/components/todo/TodoInput.js
Outdated
| } | ||
| } | ||
| > | ||
| <Row> |
There was a problem hiding this comment.
Row를 없애고 Row의 스타일링을 Form에 넣어줘도될 것 같아요~
src/components/todo/Todo.js
Outdated
| import TodoInput from './TodoInput'; | ||
| import TodoCard from './TodoCard'; | ||
|
|
||
| const Wrapper = styled.div` |
There was a problem hiding this comment.
Component 작성시 중요한 정보 순서대로 위쪽에 배치하는게 좋습니다!
컴포넌트들의 스타일링들은 비교적 중요도가 떨어지겠죠?!
맨 아래에 위치시켜주시면 됩니다~
src/components/todo/Todo.js
Outdated
| }; | ||
| } | ||
|
|
||
| onClick = (index) => { |
There was a problem hiding this comment.
Todo 컴포넌트 안에 onClick 함수가 있으니 마치 Todo 컴포넌트를 클릭했을때 발동할 것 같다는 오해의 소지가 있네요~
다른 네이밍으로 바꾸는게 좋을 것 같아요!
| } | ||
|
|
||
| onClick = (index) => { | ||
| this.setState({ todoList: [...this.state.todoList.slice(0,index),...this.state.todoList.slice(index+1)] }); |
|
피드백 반영해서 수정했습니다. 피드백 덕분에 더 좋은 코드에 대한 감도 생기고 더 나은 코드를 짤 수 있는 것 같습니다! 감사합니다. |
계속 오류가 나서 힘들었던 미션이었습니다 😢
arrow function 문법을 몰라 바인딩에 문제가 있었습니다. arrow function 문법을 다시 한 번 확인하겠습니다.
빈 배열 선언할 때 '=[]'로 하지 않아서 오류가 났는데 앞으로는 이런 실수했던 경험 잘 기억하고 같은 실수 없도록 하겠습니다!
감사합니다. 🙇♀