Skip to content

Commit 12d4512

Browse files
committed
투두리스트 상태 유효성 메서드 추가
1 parent e337536 commit 12d4512

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/TodoList.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ export default function TodoList({ $target, initialState, updateCount }) {
1313
else this.state = [];
1414

1515
this.setState = (nextState) => {
16-
this.state = nextState;
16+
const newState = validation.state(nextState);
17+
this.state = newState;
18+
setItem("todo", JSON.stringify(newState));
19+
updateCount(newState);
1720
this.render();
1821
};
1922

src/util/validation.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ const validation = {
44
throw new Error("You must use new keyword");
55
}
66
},
7+
state(todoList) {
8+
return todoList.filter(
9+
(todo) =>
10+
typeof todo?.text === "string" && typeof todo?.isCompleted === "boolean"
11+
);
12+
},
713
};
814

915
export default validation;

0 commit comments

Comments
 (0)