I have an array in my state:
this.state = {
data: [
{
quantity: 0
}
],
tempQuantity: 0
};
I want to update my data[0].quantity in a TextInput so i use:
onChangeText={tempQuantity =>
this.setState({
tempQuantity,
data: [...this.state.data, { quantity: tempQuantity }]
})
}
And i have a <Text> to show the result:
<View>
<Text>{this.state.data[0].quantity}</Text>
</View>
But I get 0 every time!
How can I update each element of each object in an array?
If I use it this way, it will work dynamically? I mean i want to create an object (with all properties of the main object) every time I press a
<Button>. [ for example:data[0]withquantityof 10 -data[1] withquantity` of 12 - and ... ]
dataon everyonChangeText.dataarray then why not add that as separate property in the state instead of an object inside data array.