I have a FlatList
and I want to show a number like quantity
of product
. So I use a state
for that. Now when I press on TouchableOpacity
to change quantity to 1 working fine in console, but I can't see any change in FlatList.
constructor(props){
super(props);
this.state={
quantity : 0,
}
Increment quantity:
incrementCount=()=>{
if(this.state.quantity != 10){
console.log(this.state.quantity);
this.setState((prevState, props) => ({
quantity: this.state.quantity + 1,
}));
}
}
FlatList:
<FlatList
data={this.state.dataSource}
renderItem={({item}) =>
<View>
<Text>{item.title}</Text>
<Text>{this.state.quantity}</Text>
<TouchableOpacity onPress={this.incrementCount} activeOpacity={0.5}>
<AntDesign name="plus" size={15}/>
</TouchableOpacity>
</View>
}
/>