Skip to content
Open
28 changes: 9 additions & 19 deletions src/components/todo/Todo.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import styled from 'styled-components';
import TodoInput from './TodoInput';
import TodoCard from './TodoCard';

const Div = styled.div`
const Wrapper = styled.div`
Copy link
Member

Choose a reason for hiding this comment

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

Component 작성시 중요한 정보 순서대로 위쪽에 배치하는게 좋습니다!
컴포넌트들의 스타일링들은 비교적 중요도가 떨어지겠죠?!
맨 아래에 위치시켜주시면 됩니다~

width: 80%;
background-color: rgb(222, 242, 167);
margin: 0px auto;
Expand All @@ -21,7 +21,6 @@ class Todo extends Component {
}

onClick = (index) => {
Copy link
Member

Choose a reason for hiding this comment

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

Todo 컴포넌트 안에 onClick 함수가 있으니 마치 Todo 컴포넌트를 클릭했을때 발동할 것 같다는 오해의 소지가 있네요~
다른 네이밍으로 바꾸는게 좋을 것 같아요!

console.log(this.state.todoList)
let newTodoList = Array.from(this.state.todoList)
newTodoList.splice(index, 1);
this.setState({ todoList: newTodoList });
Copy link
Member

Choose a reason for hiding this comment

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

이 부분도 spread operator와 slice를 이용해서 리팩토링 해보시겠어요?

Copy link
Member Author

Choose a reason for hiding this comment

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

넵 해보겠습니다!

Expand All @@ -31,34 +30,25 @@ class Todo extends Component {
if (this.state.todoList.length === 0) {
return "표시할 TODO가 없어요!";
Copy link
Member

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.

넵 리팩토링해보겠습니다

Copy link
Member Author

Choose a reason for hiding this comment

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

리팩토링 시도해봤는데 리턴에 계속 밑줄이 그어지면서 오류라고 뜨네요ㅜㅜ

Copy link
Member

Choose a reason for hiding this comment

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

앗 완전히 구조를 바꿔야해요! ㅎㅎ.. 작성스타일 차이로 볼 수도 있는 부분이라고 생각해서 꼭 고치진 않으셔도 됩니당

}
else {
let showTodoList = [];
for (let index = 0; index < this.state.todoList.length; index++) {
showTodoList.push(
<TodoCard
index={index}
todo={this.state.todoList[index]}
onClick={this.onClick}
/>);
}
return showTodoList;
}

let showTodoList = this.state.todoList.map((_todo, index) => {
Copy link
Member

Choose a reason for hiding this comment

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

  1. 추가적인 수정사항이 없으므로 let보다는 const가 적합해보이네요
  2. map함수의 결과를 그대로 return 해주셔도 됩니당

Copy link
Member Author

Choose a reason for hiding this comment

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

넵 수정하겠습니다

return <TodoCard index={index} todo={_todo} onClick={this.onClick}/>;
});
return showTodoList;
}

onSubmit = (_todo) => {
let newTodoList = Array.from(this.state.todoList);
newTodoList.push(_todo);
this.setState({
todoList: newTodoList
todoList: [...this.state.todoList,_todo]
Copy link
Member

Choose a reason for hiding this comment

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

👍

});
}

render() {
return (
<Div>
<Wrapper>
<TodoInput onSubmit={this.onSubmit}></TodoInput>
{this.getTodo()}
</Div>
</Wrapper>
);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/components/todo/TodoCard.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { Component } from 'react';
import styled from 'styled-components';

const Div = styled.div`
const CardWrapper = styled.div`
background-color: rgb(32, 122, 38);
color: white;
font-size: 1.5rem;
Expand All @@ -15,11 +15,11 @@ class TodoCard extends Component {

render() {
return (
<Div onClick={() => {
<CardWrapper onClick={() => {
this.props.onClick(this.props.index);
}}>
{this.props.index + 1}. {this.props.todo}
</Div>
</CardWrapper>
)
}
}
Expand Down
9 changes: 6 additions & 3 deletions src/components/todo/TodoInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@ const Button = styled.input`
font-size: 1.5rem;
border-radius: 0.5rem;
`
const Form = styled.form``
const Input = styled.input``


// 힌트 : Row, Input, Button
class TodoInput extends Component {

render() {
return (
<form name="addListForm"
<Form name="addListForm"
onSubmit={(e) => {
Copy link
Member

Choose a reason for hiding this comment

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

함수를 분리해서 써볼까요~

e.preventDefault();
if (e.target.todo.value === "")
Expand All @@ -30,7 +33,7 @@ class TodoInput extends Component {
}
>
<Row>
Copy link
Member

Choose a reason for hiding this comment

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

Row를 없애고 Row의 스타일링을 Form에 넣어줘도될 것 같아요~

<input
<Input
type="text"
name="todo"
placeholder="TODO를 입력하세요" />
Expand All @@ -39,7 +42,7 @@ class TodoInput extends Component {
name="addButton"
value="ADD" />
</Row>
</form>
</Form>
);
}
}
Expand Down