'How to check something while loading in expo?
I want to check if access token is present or not while splash screen is loading. How to do that in expo?
Solution 1:[1]
I found the solution :-)
``// import....
import * as SplashScreen from 'expo-splash-screen';
//.......
//.......function
const [appIsReady, setAppIsReady] = useState(false);
//.......
useEffect(()=>{
async function prepare() {
try {
await SplashScreen.preventAutoHideAsync();
await isUser(); // checking for token availability
await new Promise(resolve => setTimeout(resolve, 2000));
} catch (e) {
console.log(e);
} finally {
setAppIsReady(true);
}
};
prepare();
},[]);
const onLayoutRootView = useCallback(async () => {
if (appIsReady) {
await SplashScreen.hideAsync();
}
}, [appIsReady]);
if (!appIsReady) {
return null;
};
return (
<NavigationContainer>
<View style={{flex:1,backgroundColor:"#e0ab24"}} onLayout=
{onLayoutRootView}>
//.....(navigator)
//....
</View>
</NavigationContainer>``
follow documentation : https://docs.expo.dev/versions/latest/sdk/splash-screen/
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Dibyasundar Khatua |
