質問編集履歴
1
補足事項
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
axios deleteメソッドの使い方
|
test
CHANGED
@@ -76,9 +76,9 @@
|
|
76
76
|
|
77
77
|
};
|
78
78
|
|
79
|
-
const deleteTodo =
|
79
|
+
const deleteTodo = id => {
|
80
80
|
|
81
|
-
axios.delete(`http://localhost:3000/todos/${
|
81
|
+
axios.delete(`http://localhost:3000/todos/${id}(⬅️ここの書き方がググっても出来ませんでした!!!)`, todo).then(res => {
|
82
82
|
|
83
83
|
setTodos(todos.filter(e => e !== todo));
|
84
84
|
|
@@ -107,3 +107,69 @@
|
|
107
107
|
|
108
108
|
|
109
109
|
```
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
```Item
|
114
|
+
|
115
|
+
import React from "react";
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
import styled from "styled-components";
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
const Item = props => {
|
124
|
+
|
125
|
+
const [isDone, setIsDone] = React.useState(false);
|
126
|
+
|
127
|
+
const toggleIsDone = () => setIsDone(!isDone);
|
128
|
+
|
129
|
+
// ↑こうしないとがっつりエラーになる
|
130
|
+
|
131
|
+
// でないとsetIsDoneが永遠に作動し続ける。
|
132
|
+
|
133
|
+
const handleClick = () => props.deleteTodo(props.desc);⇦ここの引数をidにしたいです!(現状テキスト)
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
return (
|
138
|
+
|
139
|
+
<li>
|
140
|
+
|
141
|
+
<ContentText isDone={isDone}>{props.desc}</ContentText>
|
142
|
+
|
143
|
+
<DoneBtn isDone={isDone} onClick={toggleIsDone}>
|
144
|
+
|
145
|
+
{isDone ? "戻す" : "完了!"}
|
146
|
+
|
147
|
+
</DoneBtn>
|
148
|
+
|
149
|
+
<button onClick={handleClick}>削除</button>
|
150
|
+
|
151
|
+
</li>
|
152
|
+
|
153
|
+
);
|
154
|
+
|
155
|
+
};
|
156
|
+
|
157
|
+
const ContentText = styled.p`
|
158
|
+
|
159
|
+
text-decoration: ${props => (props.isDone ? "line-through" : "none")};
|
160
|
+
|
161
|
+
`;
|
162
|
+
|
163
|
+
const DoneBtn = styled.button`
|
164
|
+
|
165
|
+
color: ${props => (props.isDone ? "gray" : "black")};
|
166
|
+
|
167
|
+
`;
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
export default Item;
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
```
|