Created
May 15, 2021 19:39
-
-
Save GeoffMahugu/8f24dd45431a6079a035fb54d2ce6d4e to your computer and use it in GitHub Desktop.
This is the App.tsx file for the react-firebase app
This file contains hidden or 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, { useEffect, useState } from 'react'; | |
| import { BrowserRouter as Router, Switch, Route, RouteComponentProps } from 'react-router-dom'; | |
| import { auth } from './config/firebase'; | |
| import routes from './config/routes'; | |
| import AuthRoute from './modules/auth/AuthRouter'; | |
| import './App.css'; | |
| export interface IApplicationProps { } | |
| const App: React.FunctionComponent<IApplicationProps> = props => { | |
| const [loading, setLoading] = useState<boolean>(true); | |
| // Monitor and Update user state. | |
| useEffect(() => { | |
| auth.onAuthStateChanged(user => { | |
| if (user) { | |
| console.log('User detected.') | |
| } else { | |
| console.log('No user detected'); | |
| } | |
| setLoading(false); | |
| }) | |
| }, []); | |
| if (loading) | |
| return <div>Loding...</div> | |
| return ( | |
| <Router> | |
| <Switch> | |
| {routes.map((route, index) => | |
| <Route | |
| key={index} | |
| path={route.path} | |
| exact={route.exact} | |
| render={(routeProps: RouteComponentProps<any>) => { | |
| if (route.protected) | |
| return <AuthRoute ><route.component {...routeProps} /></AuthRoute>; | |
| return <route.component {...routeProps} />; | |
| }} | |
| />)} | |
| </Switch> | |
| </Router> | |
| ); | |
| } | |
| export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment