'React Native onPress event returning undefined
I'm having trouble returning the event object from onPress. What am I missing?
constructor(props) {
super(props)
this.state = {
user: null,
}
this.testEvent = this.testEvent.bind(this)
}
testEvent(e, id) {
console.log(e)
}
<TouchableWithoutFeedback style={styles.rightGroupContainer}
onPress={(e) => this.testEvent(e, id)}>
<Image source={this.closeIcon} style={styles.closeIcon}></Image>
</TouchableWithoutFeedback>
Solution 1:[1]
There is no e and id variables in your code.
onPress={(e) => this.testEvent(e, id)}
Solution 2:[2]
The onpress event returned undefined for me when I imported TouchableOpacity from react-native-gesture-handler. When I switched the import from react-native, it worked.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | ouflak |
