-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
52 lines (46 loc) · 1.14 KB
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { useEffect } from 'react';
import React from 'react';
import { useDispatch, useSelector } from "react-redux";
import './App.css';
import { auth } from './firebase';
import { login, logout, selectUser } from "./features/userSlice";
import Feed from './Feed';
import Login from './Login';
import Sidebar from './Sidebar';
import Widgets from "./Widgets";
import Header from "./Header";
function App() {
const user = useSelector(selectUser);
const dispatch = useDispatch();
useEffect(() => {
auth.onAuthStateChanged(userAuth => {
if (userAuth) {
dispatch(login({
email: userAuth.email,
uid: userAuth.uid,
displayName: userAuth.displayName,
photoURL: userAuth.photoURL,
//user is logged in
}))
} else {
//user is logged out
dispatch(logout());
}
})
}, [dispatch]);
return (
<div className="app">
<Header />
{!user ? (
<Login />
) : (
<div className="app__body">
<Sidebar />
<Feed />
<Widgets />
</div>
)}
</div>
);
}
export default App;