Last active
July 20, 2021 07:56
-
-
Save hadizz/5cfdc223fe8ebbf71fd17bb48b553b05 to your computer and use it in GitHub Desktop.
auth context hooks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, {Suspense} from "react" | |
import {useAuth} from "./contexts/Auth" | |
import {useHistory} from "react-router-dom"; | |
const AuthenticatedApp = React.lazy(() => import('./AuthenticatedApp')) | |
const UnauthenticatedApp = React.lazy(() => import('./UnauthenticatedApp')) | |
const App = () => { | |
const {user} = useAuth(); | |
const history = useHistory(); | |
return ( | |
<Suspense fallback={<p>loading...</p>}> | |
{user ? <AuthenticatedApp/> : <UnauthenticatedApp from={history.location}/>} | |
</Suspense> | |
) | |
} | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment