I have created a button that whenever is touched, it adds this object, {problema: '', solucion: '', key: Math.random(), index: index+1}, to this useState array, const [data, setData] = useState ([]). The constant data is used in a Flatlist that contains two TextInput, one for changing the string problema and the other to change the string solucion. My problem is that when you touch several times the button, the constant data will contain several object and I dont know how to change that specific string based on the TextInput that you use.
{
let [index, setIndex] = useState(-1);
let passingValue = { problema: '', solucion: '', key: Math.random().toString(), index: index+1 }
const [data, setData] = useState([])
const onPressPlus = () => {
setIndex(index + 1)
setData(prevState => [...prevState, passingValue])
console.log(data);
}
return (
<View>
<TouchableOpacity onPress={onPressPlus}>
<AntDesign name='pluscircle'/>
</TouchableOpacity>
<View>
<FlatList
data={data}
renderItem={itemData => (
<View style={{ flexDirection: 'row', }}>
<View>
<TextInput
placeholder="Escribe tu problema"
placeholderTextColor='black'
value={itemData.item.problema}
onChangeText={(e) => { /* I dont know how to change the value of this specific itemData.item.problema with setData()*/ }}
multiline={true}
numberOfLines={2}
/>
</View>
<View>
<TextInput
placeholder="Escribe tu problema"
placeholderTextColor='black'
value={itemData.item.solucion}
onChangeText={(e) => { /* I dont know how to change the value of this specific itemData.item.solucion with setData() */ }}
multiline={true}
numberOfLines={2}
/>
</View>
</View>
)}
keyExtractor={itemData => itemData.key}
/>
</View>
</View>
)
}