In my React Native
app, I\'m using React Navigation 5
and trying to route users to authentication stack if the user is not authenticated i.e. there\'s
You have to wait for getting a token from AsyncStorage like this.
const App = () => {
const [loading, setLoading] = usState(true)
const [authenticated, setAuthenticated] = usState(false)
useEffect(()=>{async()=>{
const authenticatedUser = await AsyncStorage.getItem("access_token");
setLoading(false)
if(authenticatedUser !== null) setAuthenticated(true)
}},[])
const authenticatedUser = AsyncStorage.getItem("access_token");
return (
{ loading &&
}
{
authenticated && !loading
?
:
}
);
};
export default App;