ryanwaite28
ryanwaite28

Reputation: 2050

React Navigation - Stack Navigation Button

So i making a react app and there is a screen where i have a button on the right side of the header. The problem is that it crashes when clicked. Here is the code inside the react component (placed right above the constructor method):

static navigationOptions = {
    headerRight: <Ionicons style={{marginRight: 15}} name={prefix + 'power'}
                    color={colors.app_secondary_color} size={30} onPress={() => this.signout()}/>
  }

And here is the error:

_this3.signout is not a function. (In '_this3.signout()', '_this3.signout' is undefined)

onPress
    ProfileView.js:25:80

i'm thinking the this reference doesn't reach that far?

Upvotes: 0

Views: 79

Answers (1)

Alexander Vitanov
Alexander Vitanov

Reputation: 4139

There is no this.signout because navigationOptions is static. You can achieve what you want by extracting the button into a different component and connecting it to the redux store, then dispatch a signout action onPress

Upvotes: 1

Related Questions