title: React Navigation V5: Navigate to different Screen
body: <p>I am using <a href="https://callstack.github.io/react-native-paper/menu.html" rel="nofollow noreferrer">React-Native-Paper Menu</a> on the header to show two items: <code>Logout</code> and <code>Profile</code></p>
  
  <blockquote>
    <p>However, I can't seem to navigate to different screen when pressing
    <code>Logout</code> item.</p>
  </blockquote>
  
  <p><strong>I have included snack workable example, code snippet, and screenshot below:</strong></p>
  
  <p><a href="https://snack.expo.io/fXm9aEOlC" rel="nofollow noreferrer"><strong><em>Snack Example</em></strong></a></p>
  
  <p><strong><em>Code Snippet:</em></strong></p>
  
  <p><em>App.js</em></p>
  
  <pre><code>import { TextInput, Button, Menu, Divider, Provider } from 'react-native-paper';
  import MaterialCommunityIcons from 'react-native-vector-icons/MaterialCommunityIcons';
  import AntDesign from 'react-native-vector-icons/AntDesign';
  
  import Register from './Register';
  import Logout from './Logout';
  
  
  const Stack = createStackNavigator();
  
  
  const CustomMenu = () =&gt; {
    const [showMenu, setShowMenu] = React.useState(false);
  
    return (
      &lt;View style={{}}&gt;
        &lt;Menu
          visible={showMenu}
          onDismiss={() =&gt; setShowMenu(false)}
          anchor={
            &lt;TouchableOpacity onPress={() =&gt; setShowMenu(true)}&gt;
              &lt;MaterialCommunityIcons
                name="earth"
                size={30}
                style={{ color: 'black' }}
              /&gt;
            &lt;/TouchableOpacity&gt;
          }&gt;
          &lt;Menu.Item 
            title="Logout"
            onPress={() =&gt; {
              setShowMenu(false)
              /* THE FOLLOWING DOESN'T WORK */
              //navigation.navigate('Logout')
            }}  
          /&gt;
          &lt;Divider /&gt;
          &lt;Menu.Item 
            onPress={() =&gt; {
              setShowMenu(false)
            }} 
            title="Profile" 
          /&gt;
        &lt;/Menu&gt;
      &lt;/View&gt;
    );
  };
  
  
  
  function App() {
    return (
      &lt;Provider&gt;
        &lt;NavigationContainer&gt;
          &lt;Stack.Navigator&gt;
            &lt;Stack.Screen
              name="Register"
              component={Register}
              options={({ navigation, route }) =&gt; ({
  
                      headerTitle: () =&gt; (
                          &lt;View style={{ flexDirection: 'row' }}&gt;
                            {
                                      /*THIS WORKS*/
                                      &lt;TouchableOpacity
                                          onPress={() =&gt; navigation.navigate('Logout')}
                                      &gt;
                                          &lt;MaterialCommunityIcons name="settings" size={30} style={{ 
                                           color: 'black' }} /&gt;
                                      &lt;/TouchableOpacity&gt;
                                      /*THIS WORKS*/
                           }
  
                              &lt;View&gt;&lt;CustomMenu /&gt;&lt;/View&gt;
  
                              &lt;TouchableOpacity
                                  onPress={() =&gt; navigation.navigate('MenuV2')}
                              &gt;
                                  &lt;Text&gt;
                                      Menu
                                  &lt;/Text&gt;
                              &lt;/TouchableOpacity&gt;
                          &lt;/View&gt;
                      ),
                      headerStyle: {
                          backgroundColor: '#2e46ff',
                      },
                  })}
            /&gt;
  
            &lt;Stack.Screen name="Logout" component={Logout}/&gt;
          &lt;/Stack.Navigator&gt;
        &lt;/NavigationContainer&gt;
      &lt;/Provider&gt;
    );
  }
  
  export default App;
  </code></pre>
  
  <p><strong><em>Screenshot:</em></strong></p>
  
  <p><a href="https://i.stack.imgur.com/u1ufR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/u1ufR.png" alt="Screen"></a></p>