Lucky_girl
Lucky_girl

Reputation: 4883

Error, while try to navigate to another screen using StackNavigator in React Navigation

I'm using StackNavigator, I have added button in the toolbar, and when clicking that button, I want to navigate to another screen, instead of that, when I press button, I get an error:

"Can't find variable navigate"

. How to fix that?

  static navigationOptions = {
      title: 'Review Jobs',
      headerRight: <Button tittle="Settings" onPress={()=> navigate('settings') } />
      }   

Upvotes: 0

Views: 110

Answers (2)

bennygenel
bennygenel

Reputation: 24680

If you are trying to use methods from navigation while setting navigationOptions you can use an arrow function rather than just setting it as a plain object

Example

static navigationOptions = ({navigation}) => ({
  title: 'Review Jobs',
  headerRight: <Button tittle="Settings" onPress={()=> navigation.navigate('settings') } />
});

Upvotes: 2

Muhammad Usman
Muhammad Usman

Reputation: 358

The right syntax would be

static navigationOptions = ({ navigation }) => ({ title: 'Review Jobs', headerRight: <Button tittle="Settings" onPress={()=> navigation.navigate('settings') } /> });

Upvotes: 3

Related Questions