0
votes

i m trying to use react-navigation to implement an onPress handler which allows me to navigate to a screen called tasks

the below code shows the headerRight just fine. however, when i click on the headerRight button, i get the following error

"Undefined is not an object (evaluating _this2.props.navigation) on my expo simulator".

Anyone knows what could have gone wrong with my onPress handler? Tq

static navigationOptions = {
    title: 'List',

    headerRight: (
        <Button
         title='Add Task'
         onPress={() => this.props.navigation.navigate('task')}
         backgroundColor='rgba(0,0,0,0)'
         color='rgba(0,122,255,1)'
        />) 

}
1

1 Answers

1
votes

I managed to get the codes working

hope this can help those using react-navigation and wanting to render a workable headerRight

static navigationOptions = ({navigation}) => ({
    title: 'List',
    headerRight: <Button
        title= 'Add Task'
        onPress={() => navigation.navigate('task')}
        backgroundColor='rgba(0,0,0,0)'
        color='rgba(0,122,255,1)'
    />
});