Andrew Lastrapes
Andrew Lastrapes

Reputation: 187

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>

Upvotes: 0

Views: 441

Answers (2)

Richard Lii
Richard Lii

Reputation: 1

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.

Upvotes: 0

plasticcocoa
plasticcocoa

Reputation: 79

There is no e and id variables in your code.

onPress={(e) => this.testEvent(e, id)}

Upvotes: 0

Related Questions