Skip to content

Instantly share code, notes, and snippets.

@hadizz
Last active July 20, 2021 07:56
Show Gist options
  • Save hadizz/5cfdc223fe8ebbf71fd17bb48b553b05 to your computer and use it in GitHub Desktop.
Save hadizz/5cfdc223fe8ebbf71fd17bb48b553b05 to your computer and use it in GitHub Desktop.
auth context hooks
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