General Baguettson
General Baguettson

Reputation: 163

react native: react-navigation crashes when navigating with headerRight

why doesn't this works ?:

headerRight: <Button title="Prout" onPress={() => this.props.navigation.navigate('MenuCQ')}/>

When pressed, expo just crashes, with no error message at all. The onPress works on a button in my render method, so it should work in my headerRight, right ?

If not pushed, all the rest works, and the exact same button in my render method works well too.

Upvotes: 0

Views: 686

Answers (1)

Ravi Raj
Ravi Raj

Reputation: 6677

I think your using react-navigation, you cannot access 'this' inside screen navigationOptions as of v1.0.0-beta.11. But you will get navigation object of that screen which you can use to navigate as shown below

navigationOptions: ({navigation}) => ({
      headerRight: <Button title="Prout" onPress={() => navigation.navigate('MenuCQ')}/>
    }),

Upvotes: 1

Related Questions