In my react-native app, I have a component for my header with back button. It works except for when I click the back button and it gives me this error: undefined is not an object (evaluating this.props.navigation)
So I followed the docs here and tried using withNavigation
. But I still get the same error. What am I doing wrong?
import React from 'react'
import { StyleSheet, Text, View, TouchableOpacity } from 'react-native'
import { withNavigation } from 'react-navigation';
const HeaderWithBackBtn = (props) => {
return (
<View style={styles.container}>
{/* Back button */}
<TouchableOpacity
style={{width: 100}}
onPress={() => this.props.navigation.goBack()}>
<Text style={styles.backBtn}>Back</Text>
</TouchableOpacity>
<Text style={styles.text}> {props.screen} </Text>
{/* Placeholder button */}
<Text style={{width: 100}}></Text>
</View>
)
}
const styles = StyleSheet.create({
...
});
export default withNavigation(HeaderWithBackBtn);