回答編集履歴
2
ソース修正
test
CHANGED
@@ -55,3 +55,63 @@
|
|
55
55
|
</tr>
|
56
56
|
|
57
57
|
```
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
または、idを使ってstatusをトグルする要素を指定してもええ。修正箇所は、上に同じ2箇所や。
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
```diff
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
setTodos(newTodos.map((e, i) => ({ ...e, id: i + 1 })));
|
70
|
+
|
71
|
+
};
|
72
|
+
|
73
|
+
- const toggle = () => {
|
74
|
+
|
75
|
+
- setComment((prevState) => !prevState);
|
76
|
+
|
77
|
+
+ const toggle = (todoId) => {
|
78
|
+
|
79
|
+
+ setTodos(todos.map((todo, i) =>
|
80
|
+
|
81
|
+
+ todoId === todo.id ? {
|
82
|
+
|
83
|
+
+ ...todo,
|
84
|
+
|
85
|
+
+ status: todo.status === 'incomplete' ? 'completed' : 'incomplete', // completed は「完了」を表す
|
86
|
+
|
87
|
+
+ } : todo));
|
88
|
+
|
89
|
+
};
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
return (
|
94
|
+
|
95
|
+
```
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
```diff
|
100
|
+
|
101
|
+
<td>{todo.id}</td>
|
102
|
+
|
103
|
+
<td>{todo.comment}</td>
|
104
|
+
|
105
|
+
<td>
|
106
|
+
|
107
|
+
- <button onClick={toggle}>{comment ? "作業中" : "完了"}</button>
|
108
|
+
|
109
|
+
+ <button onClick={() => toggle(todo.id)}>{todo.status === 'incomplete' ? "作業中" : "完了"}</button>
|
110
|
+
|
111
|
+
<button onClick={() => handleDelete(index)}>削除</button>
|
112
|
+
|
113
|
+
</td>
|
114
|
+
|
115
|
+
</tr>
|
116
|
+
|
117
|
+
```
|
1
ソース修正
test
CHANGED
@@ -3,6 +3,12 @@
|
|
3
3
|
|
4
4
|
|
5
5
|
```diff
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
setTodos(newTodos.map((e, i) => ({ ...e, id: i + 1 })));
|
10
|
+
|
11
|
+
};
|
6
12
|
|
7
13
|
- const toggle = () => {
|
8
14
|
|
@@ -20,14 +26,32 @@
|
|
20
26
|
|
21
27
|
+ } : todo));
|
22
28
|
|
29
|
+
};
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
return (
|
34
|
+
|
23
35
|
```
|
24
36
|
|
25
37
|
|
26
38
|
|
27
39
|
```diff
|
28
40
|
|
41
|
+
<td>{todo.id}</td>
|
42
|
+
|
43
|
+
<td>{todo.comment}</td>
|
44
|
+
|
45
|
+
<td>
|
46
|
+
|
29
47
|
- <button onClick={toggle}>{comment ? "作業中" : "完了"}</button>
|
30
48
|
|
31
49
|
+ <button onClick={() => toggle(index)}>{todo.status === 'incomplete' ? "作業中" : "完了"}</button>
|
32
50
|
|
51
|
+
<button onClick={() => handleDelete(index)}>削除</button>
|
52
|
+
|
53
|
+
</td>
|
54
|
+
|
55
|
+
</tr>
|
56
|
+
|
33
57
|
```
|