[Solved] Android App Splash screen not loading instantly – React Native

Abdul Wasay Asks: Android App Splash screen not loading instantly – React Native
I’m relatively new to react native and I’ve been trying to write this code where I get user type (i.e Admin or Mod) from my database and switching to the respective drawer navigator. In between switching I’m loading my splash screen. My problem is say I login as an Admin then logout and try to login as a Mod, for a split second before my Splash Screen is loaded, My previous screen (i.e Admin screen) renders. Any help would be greatly appreciated.

Code:
const App = () => {
  const [isLoading, setIsLoading] = useState(true);
  const [userType, setUserType] = useState(null);
  const [User, setUser] = useState(null);

  const getUserType = async () => {
    //Getting UserType from Database
    setUserType(fetchedUserType);
  };

  const onAuthStateChanged = user => {
    setUser(user);
    setTimeout(() => {
      if (isLoading) setIsLoading(false);
    }, 2000);
  };

  useEffect(() => {
    const subscriber = auth().onAuthStateChanged(onAuthStateChanged);
    return subscriber;
  });

  useEffect(() => {
    //clearing the UserType and making the splash screen render
    setUserType(null);
    setIsLoading(true);
    let Mounted = true;
    getUserType().then(() => {
      if (Mounted) {
        setIsLoading(false);
      }
      return function cleanup() {
        Mounted = false;
      };
    });
  }, [User]);

  if (isLoading) {
    return <Splash></Splash>;
  } else if (User === null) {
    return <Login></Login>;
  } else if (userType === 'Admin') {
    return <AdminDrawerNavigator></AdminDrawerNavigator>;
  } else if (userType === 'Mod') {
    return <ModDrawerNavigator></ModDrawerNavigator>;
  } else {
    return <Fatal></Fatal>;
  }
};

Ten-tools.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your response here to help other visitors like you. Thank you, Ten-tools.