I have a series of react native TouchableHighlights, each with a key prop (they are generated from an iterator). I want to give each an onPress function that is aware of its key parameter.
I have read that class based arrow functions are generally best practice, so I tried this:
handlePress = (event) => {
console.log(event.target.key)
}
<TouchableOpacity key={key} onPress={this.handlePress} />
No dice, event is null.
So then I tried:
handlePress = (key) => {
console.log(key)
}
<TouchableOpacity key={key} onPress={() => this.handlePress(key)} />
This works
However, this also works:
handlePress(key) {
console.log(key)
}
<TouchableOpacity key={key} onPress={() => this.handlePress(key)} />
I thought that either one, or the other would fail. Are these functionally identical, or is there some subtlety that I'm missing?