After updating expo I keep getting this error that says:
expo-app-loading is deprecated in favor of expo-splash-screen: use SplashScreen.preventAutoHideAsync() and SplashScreen.hideAsync() instead.
Here's the my code in App.js
import React, { useState } from 'react'
import AppLoading from 'expo-app-loading';
import { NavigationContainer } from '@react-navigation/native';
import AuthNavigator from './navigation/AuthNavigator';
import AppNavigator from './navigation/AppNavigator';
import AuthContext from './auth/context';
import authStorage from './auth/storage';
const App = () => {
const [user, setUser] = useState();
const [isReady, setIsReady] = useState(false);
const restoreToken = async () => {
const token = await authStorage.getToken();
if (!token) return;
setUser(JSON.parse(token));
}
if (!isReady) {
return (
<AppLoading
startAsync={restoreToken}
onFinish={() => setIsReady(true)}
onError={console.warn}
/>
);
}
return (
<AuthContext.Provider value={{user, setUser}}>
<NavigationContainer>
{ user ? <AppNavigator /> : <AuthNavigator/> }
</NavigationContainer>
</AuthContext.Provider>
)
}
My question is how will I implement my below section code indicated below with the one expo recommend cause the expo one is used for font mine is for logged in uses.
const restoreToken = async () => {
const token = await authStorage.getToken();
if (!token) return;
setUser(JSON.parse(token));
}
and this:
<AppLoading
startAsync={restoreToken}
onFinish={() => setIsReady(true)}
onError={console.warn}
/>
expo recommended code with is this:
import React, { useCallback, useEffect, useState } from 'react';
import { Text, View } from 'react-native';
import Entypo from '@expo/vector-icons/Entypo';
import * as SplashScreen from 'expo-splash-screen';
import * as Font from 'expo-font';
SplashScreen.preventAutoHideAsync();
export default function App() {
const [appIsReady, setAppIsReady] = useState(false);
useEffect(() => {
async function prepare() {
try {
await new Promise(resolve => setTimeout(resolve, 2000));
} catch (e) {
console.warn(e);
} finally {
// Tell the application to render
setAppIsReady(true);
}
}
prepare();
}, []);
const onLayoutRootView = useCallback(async () => {
if (appIsReady) {
await SplashScreen.hideAsync();
}
}, [appIsReady]);
if (!appIsReady) {
return null;
}
Thank for your help, I will appreciate if you help recreate my code with the expo recommended code expo-splash-screen