質問編集履歴
1
内容編集
test
CHANGED
File without changes
|
test
CHANGED
@@ -133,3 +133,127 @@
|
|
133
133
|
|
134
134
|
|
135
135
|
```
|
136
|
+
|
137
|
+
---
|
138
|
+
|
139
|
+
追記①
|
140
|
+
|
141
|
+
```JS
|
142
|
+
|
143
|
+
import React, { useState } from "react";
|
144
|
+
|
145
|
+
import { View, Button, Text } from "react-native";
|
146
|
+
|
147
|
+
import { TextInput } from "react-native-gesture-handler";
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
function Item({ setText, handleMakeNew, handleDelete, i }) {
|
152
|
+
|
153
|
+
return (
|
154
|
+
|
155
|
+
<View>
|
156
|
+
|
157
|
+
<Text>{i}</Text>
|
158
|
+
|
159
|
+
<TextInput
|
160
|
+
|
161
|
+
onChange={(e) => {
|
162
|
+
|
163
|
+
setText(i, e.nativeEvent.text);
|
164
|
+
|
165
|
+
}}
|
166
|
+
|
167
|
+
/>
|
168
|
+
|
169
|
+
<View>
|
170
|
+
|
171
|
+
<Button
|
172
|
+
|
173
|
+
title="追加"
|
174
|
+
|
175
|
+
onPress={() => {
|
176
|
+
|
177
|
+
handleMakeNew();
|
178
|
+
|
179
|
+
}}
|
180
|
+
|
181
|
+
/>
|
182
|
+
|
183
|
+
<Button
|
184
|
+
|
185
|
+
title="削除"
|
186
|
+
|
187
|
+
onPress={() => {
|
188
|
+
|
189
|
+
handleDelete();
|
190
|
+
|
191
|
+
}}
|
192
|
+
|
193
|
+
/>
|
194
|
+
|
195
|
+
</View>
|
196
|
+
|
197
|
+
</View>
|
198
|
+
|
199
|
+
);
|
200
|
+
|
201
|
+
}
|
202
|
+
|
203
|
+
|
204
|
+
|
205
|
+
export default function TestListItem() {
|
206
|
+
|
207
|
+
const [count, setCount] = useState(1);
|
208
|
+
|
209
|
+
const [texts, setTexts] = useState({});
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
function handleMakeNew() {
|
214
|
+
|
215
|
+
setCount((v) => v + 1);
|
216
|
+
|
217
|
+
}
|
218
|
+
|
219
|
+
function handleDelete() { //①ここで連想配列の要素を削除
|
220
|
+
|
221
|
+
setCount((v) => v - 1);
|
222
|
+
|
223
|
+
|
224
|
+
|
225
|
+
}
|
226
|
+
|
227
|
+
return (
|
228
|
+
|
229
|
+
<View>
|
230
|
+
|
231
|
+
<Text>{JSON.stringify(texts)}</Text>
|
232
|
+
|
233
|
+
{[...Array(count).keys()].map((i) => (
|
234
|
+
|
235
|
+
<Item
|
236
|
+
|
237
|
+
handleMakeNew={handleMakeNew}
|
238
|
+
|
239
|
+
handleDelete={handleDelete}
|
240
|
+
|
241
|
+
setText={(i, text) => setTexts((prev) => ({ ...prev, [i]: text }))}
|
242
|
+
|
243
|
+
key={i}
|
244
|
+
|
245
|
+
i={i}
|
246
|
+
|
247
|
+
/>
|
248
|
+
|
249
|
+
))}
|
250
|
+
|
251
|
+
</View>
|
252
|
+
|
253
|
+
);
|
254
|
+
|
255
|
+
}
|
256
|
+
|
257
|
+
|
258
|
+
|
259
|
+
```
|