첫 주 과제에 대한 코드 리뷰를 받았다.
코드 리뷰에 대한 모든 내용을 이해하고 수정하진 못했지만 수정을 완료한 내용은 다음과 같다.
완료한 부분에 대한 내용은 주로 코드를 좀 더 짧고 효율적이게 짜는 피드백이다.
❗ 변경 전
//exercise/4th/김형석/js/src/App.js
addTodo(text) {
const { todoObj } = this.state;
const index = Math.max(0, ...todoObj.map((v) => v.index)) + 1;
const isDone = false;
const time = new Date().toLocaleString();
this.setState({
todoObj: [...todoObj, { index, text, isDone, time }],
});
💻변경 후
//exercise/4th/김형석/js/src/App.js
addTodo(text) {
const { todoObj } = this.state;
const index = todoObj.length - 1;
const isDone = false;
const time = new Date().toLocaleString();
this.setState({
todoObj: [...todoObj, { index, text, isDone, time }],
});
}
❗ 변경 전
//exercise/4th/김형석/js/src/App.js
deleteTodo(index) {
const todoObj = [...this.state.todoObj];
todoObj.splice(
todoObj.findIndex((v) => v.index === index),
1
);
this.setState({ todoObj });
}
💻변경 후
//exercise/4th/김형석/js/src/App.js
deleteTodo(index) {
const todoObj = [...this.state.todoObj].filter(
(item) => item.index !== index
);
this.setState({ todoObj });
}
'FE-kit JavaScript' 카테고리의 다른 글
| [FE 스터디] 리뷰 (0) | 2021.08.23 |
|---|---|
| [FE 스터디] Week #3 (0) | 2021.08.23 |
| [FE 스터디] Mission 3 코드 리뷰 (0) | 2021.08.23 |
| [FE 스터디] Week #2 (0) | 2021.08.23 |
| [FE 스터디] Week #1 (0) | 2021.07.30 |