So my code is :
export default class MyClass extends Component {
constructor(props) {
super(props);
this.state = {
data: [
{id: 101, name:"One", thevalue:11},
{id: 102, name:"Two", thevalue:22},
{id: 103, name:"three", thevalue:33}
]
}
}
handleOnPress() {
<< HOW DO I CODE THIS ?? >>
I want to increase the number count in thevalue of the pressed item
}
render() {
return(
<FlatList
data = {this.state.data}
renderItem = {
({item}) =>
<TouchableOpacity onPress={this.handleOnPress} >
<Text> {item.name} + {item.thevalue} </Text>
</TouchableOpacity>
}
/>
)
}
}
I want to be able to increase the count of the thevalue
of only the item clicked. So I should do a setState
right? But how do I know for which item I need to run that on? Do I need to pass the id
of the item clicked to the function? If yes, how do I do that?
Many thanks.
UPDATE1:
handleOnPress(id) {
this.setState({
thevalue: this.state.thevalue+1
});
}