Skip to content

Instantly share code, notes, and snippets.

@bogoslavskiy
Created March 5, 2020 17:45
Show Gist options
  • Save bogoslavskiy/80dd97dec22fb5df0cf625f27a73d281 to your computer and use it in GitHub Desktop.
Save bogoslavskiy/80dd97dec22fb5df0cf625f27a73d281 to your computer and use it in GitHub Desktop.
import React from 'react';
import { NavigationContainer } from '@react-navigation/native';
import { AuthContext, getUserFromStorage } from '../contexts/AuthContext';
import { MainStackScreens } from './MainStack';
import { AuthStackScreens } from './AuthStack';
export const Routes: React.FC = () => {
const [loading, setLoading] = React.useState(true);
const { setUser, user } = React.useContext(AuthContext);
React.useEffect(() => {
getUserFromStorage()
.then((user) => {
if (user) {
setUser(user);
}
setLoading(false);
})
.catch((err) => {
console.log(err);
setLoading(false);
});
}, []);
if (loading) {
return null;
}
return (
<NavigationContainer
theme={{
dark: false,
colors: {
primary: '#007BFF',
background: '#FFF',
card: '#FFF',
text: '#262626',
border: 'transparent',
}
}}
>
{user ? <MainStackScreens /> : <AuthStackScreens />}
</NavigationContainer>
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment