Skip to content

Commit ca37ecd

Browse files
committed
초기값 유효성 검사
1 parent 71703be commit ca37ecd

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/TodoCount.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ export default function TodoCount({ $target, initialCount }) {
66
const $container = document.createElement("div");
77
$target.appendChild($container);
88

9-
this.state = initialCount;
9+
if (initialCount.total && initialCount.done) {
10+
this.state = initialCount;
11+
} else this.state = { total: 0, done: 0 };
1012

1113
this.setState = (nextState) => {
1214
this.state = nextState;

src/TodoList.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ export default function TodoList({ $target, initialState, updateCount }) {
1010
const $todoList = document.createElement("div");
1111
$target.appendChild($todoList);
1212

13-
this.state = initialState;
13+
if (Array.isArray(initialState)) this.state = initialState;
14+
else this.state = [];
1415

1516
this.setState = (nextState) => {
1617
this.state = nextState;

0 commit comments

Comments
 (0)