title: Can't change variable when using Firebase onAuthStateChanged
body: <p>I'm writing an app in React Native and I'm trying to make the app change screen automatically depending on if the user is logged in or not.</p>
  <p>Everything works except that the variable isSignedIn is undefined so what I need help with is how to define it inside onAuthStateChanged.</p>
  <p>Thankful for help!</p>
  <p>Here is my code:</p>
  <pre><code>import { StatusBar } from 'expo-status-bar';
  import { StyleSheet, Text, View } from 'react-native';
  import React, { useEffect, useState } from 'react';
  import { NavigationContainer, useNavigation } from '@react-navigation/native';
  import { createNativeStackNavigator } from '@react-navigation/native-stack';
  import { createMaterialBottomTabNavigator } from '@react-navigation/material-bottom-tabs';
  import { useFonts } from 'expo-font';
  import { getAuth, onAuthStateChanged } from &quot;firebase/auth&quot;;
  import { auth } from './app/config/firebase';
  
  import IntroSliderScreen from './app/screens/introSlider';
  import FirstScreenScreen from './app/screens/firstScreen';
  import LogInScreen from './app/screens/logIn';
  import OverrideScreen from './app/screens/override';
  import SignUpScreen from './app/screens/signUp';
    import HomeScreen from './app/screens/mainTabs/home';
    import KartaScreen from './app/screens/mainTabs/karta';
    import MatScreen from './app/screens/mainTabs/mat';
    import MoreScreen from './app/screens/mainTabs/more';
    import ProgramScreen from './app/screens/mainTabs/program';
      import Push from './app/config/push';
  
  
  
  const Stack = createNativeStackNavigator();
  const Tab = createMaterialBottomTabNavigator ();
  
  
  
  
  
  function MainTabs() {
    return(
      &lt;Tab.Navigator&gt;
        &lt;Tab.Screen name=&quot;Home&quot; component={HomeScreen} /&gt;
        &lt;Tab.Screen name=&quot;Program&quot; component={ProgramScreen} /&gt;
        &lt;Tab.Screen name=&quot;Karta&quot; component={KartaScreen} /&gt;
        &lt;Tab.Screen name=&quot;Mat&quot; component={MatScreen} /&gt;
        &lt;Tab.Screen name=&quot;More&quot; component={MoreScreen} /&gt;
      &lt;/Tab.Navigator&gt;
    );
  }
  
  
  
  export default function App() {
    
    const [loaded] = useFonts({
      PirataOne: require('./app/assets/fonts/PirataOne-Regular.ttf'),
      RobotoMono: require('./app/assets/fonts/RobotoMono-VariableFont_wght.ttf'),
    });
    if (!loaded) {
      return null;
    };
  
    var isSignedIn;
    
    //const [isSignedIn, setIsSignedIn] = useState(false);
  
    onAuthStateChanged(auth, (user) =&gt; {
  
      if (user) {
        // User is signed in
        // https://firebase.google.com/docs/reference/js/firebase.User
        const uid = user.uid;
        // ...
        
        console.log('Inloggad med UserID: ' + uid);
        //setIsSignedIn(true);
        
      } else {
        // User is signed out
        // ...
        console.log('Ej inloggad');
      }
    });
  
    return (
      &lt;NavigationContainer&gt;
        {isSignedIn ? (
              &lt;Stack.Navigator&gt;
                &lt;Stack.Screen name='MainTabs' component={MainTabs} /&gt;
                &lt;Stack.Screen name=&quot;IntroSliderScreen&quot; component={IntroSliderScreen} /&gt;
              &lt;/Stack.Navigator&gt;
        ) : (
              &lt;Stack.Navigator&gt;
                &lt;Stack.Screen options={{headerShown: false}} name=&quot;FirstScreenScreen&quot; component={FirstScreenScreen} /&gt;
                &lt;Stack.Screen name=&quot;SignUpScreen&quot; component={SignUpScreen} /&gt;
                &lt;Stack.Screen name=&quot;LogInScreen&quot; component={LogInScreen} /&gt;
              &lt;/Stack.Navigator&gt;
        )}
      &lt;/NavigationContainer&gt;
    );
  }
  
  /* &lt;Stack.Group navigationKey={isSignedIn ? 'user' : 'guest'}&gt;
      &lt;Stack.Screen name=&quot;OverrideScreen&quot; component={OverrideScreen} /&gt;
      &lt;Stack.Screen name=&quot;Push&quot; component={Push} /&gt;
    &lt;/Stack.Group&gt; */
  
  
  </code></pre>