Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

React Native Root Element, deciding on async call

import { ActivityIndicator } from "react-native";


const RootElement = () => {
  const [loggedIn, setLoggedIn] = useState(false);
  const [loading, setLoading] = useState(true);

  useEffect(() => {
    (async () => {
      try {
        const data = await getLoginSession();
        if (data != null) {
          setLoggedIn(true);
        }
      } catch (error) {
        setLoggedIn(false);
      }
      setLoading(false);
    })();
  }, []);

  return (
    <>
      {!loading ? (
        loggedIn ? (
          <ThemeProvider>
            <NavigationContainer>
              <AppNavigation />
            </NavigationContainer>
          </ThemeProvider>
        ) : (
          <ThemeProvider>
            <Login />
          </ThemeProvider>
        )
      ) : (
        <ActivityIndicator size="large" color="#00ff00" />
      )}
    </>
  );
};
Comment

PREVIOUS NEXT
Code Example
Javascript :: React Native : Add a band of color in the background 
Javascript :: How to spread state into a specific array 
Javascript :: Delete a field from Firebase Firestore where the field/key has a period/punctuation (".") - modular v9 JavaScript SDK 
Javascript :: Error thrown after ending the audio track / array of tracks in React Native Track Player 
Javascript :: .push( ) is not updating the variable 
Javascript :: What is the best way to download mulitple images using jquery 
Javascript :: adding to an array in js 
Javascript :: fill array with random numbers javascript using arrow function 
Javascript :: setup app files in node js 
Javascript :: string split into three non empty combination js 
Javascript :: p5 filter 
Javascript :: filter a object array tree javascript 
Javascript :: Another Example In JavaScript Event Delegation 
Javascript :: javascript scrolltoview vue 
Javascript :: chat v2 msg and time good 
Javascript :: bullet mechanism in phaser 
Javascript :: convert json date to java date 
Javascript :: javascript code to decide even or odd number in html using visual studio 
Javascript :: react router how to prevent navlink from two classes 
Javascript :: cannot setState in event handler 
Javascript :: how to return data from function in javascript 
Javascript :: check if first array contains all elements javascript 
Javascript :: Looping through array, fetching tweets and returning new reversed array javascript react 
Javascript :: check token balance of an address in js 
Javascript :: How to Loop Through an Array with a for Loop in JavaScript 
Javascript :: Backbone With Express 
Javascript :: clear an array 
Javascript :: react get variable from child component 
Javascript :: redirect router v6 
Javascript :: ar.js 
ADD CONTENT
Topic
Content
Source link
Name
1+9 =