質問編集履歴
1
内容編集
title
CHANGED
File without changes
|
body
CHANGED
@@ -65,4 +65,66 @@
|
|
65
65
|
);
|
66
66
|
}
|
67
67
|
|
68
|
+
```
|
69
|
+
---
|
70
|
+
追記①
|
71
|
+
```JS
|
72
|
+
import React, { useState } from "react";
|
73
|
+
import { View, Button, Text } from "react-native";
|
74
|
+
import { TextInput } from "react-native-gesture-handler";
|
75
|
+
|
76
|
+
function Item({ setText, handleMakeNew, handleDelete, i }) {
|
77
|
+
return (
|
78
|
+
<View>
|
79
|
+
<Text>{i}</Text>
|
80
|
+
<TextInput
|
81
|
+
onChange={(e) => {
|
82
|
+
setText(i, e.nativeEvent.text);
|
83
|
+
}}
|
84
|
+
/>
|
85
|
+
<View>
|
86
|
+
<Button
|
87
|
+
title="追加"
|
88
|
+
onPress={() => {
|
89
|
+
handleMakeNew();
|
90
|
+
}}
|
91
|
+
/>
|
92
|
+
<Button
|
93
|
+
title="削除"
|
94
|
+
onPress={() => {
|
95
|
+
handleDelete();
|
96
|
+
}}
|
97
|
+
/>
|
98
|
+
</View>
|
99
|
+
</View>
|
100
|
+
);
|
101
|
+
}
|
102
|
+
|
103
|
+
export default function TestListItem() {
|
104
|
+
const [count, setCount] = useState(1);
|
105
|
+
const [texts, setTexts] = useState({});
|
106
|
+
|
107
|
+
function handleMakeNew() {
|
108
|
+
setCount((v) => v + 1);
|
109
|
+
}
|
110
|
+
function handleDelete() { //①ここで連想配列の要素を削除
|
111
|
+
setCount((v) => v - 1);
|
112
|
+
|
113
|
+
}
|
114
|
+
return (
|
115
|
+
<View>
|
116
|
+
<Text>{JSON.stringify(texts)}</Text>
|
117
|
+
{[...Array(count).keys()].map((i) => (
|
118
|
+
<Item
|
119
|
+
handleMakeNew={handleMakeNew}
|
120
|
+
handleDelete={handleDelete}
|
121
|
+
setText={(i, text) => setTexts((prev) => ({ ...prev, [i]: text }))}
|
122
|
+
key={i}
|
123
|
+
i={i}
|
124
|
+
/>
|
125
|
+
))}
|
126
|
+
</View>
|
127
|
+
);
|
128
|
+
}
|
129
|
+
|
68
130
|
```
|