-
Notifications
You must be signed in to change notification settings - Fork 0
/
Root.js
32 lines (26 loc) · 783 Bytes
/
Root.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
import React, { useState, useEffect } from "react";
import MainDrawer from "./MainDrawer";
import AuthStack from "./AuthStack";
import Firebase from "firebase";
import { connect } from "react-redux";
import { AppLoading } from "expo";
import { autoLogin } from "./redux/actions";
function Root(props) {
const [isLoading, setIsLoading] = useState(true);
useEffect(() => {
Firebase.auth().onAuthStateChanged((user) => {
if (user) {
props.autoLogin();
}
setIsLoading(false);
});
}, []);
if (isLoading) {
return <AppLoading />;
}
return props.isLoggedIn ? <MainDrawer /> : <AuthStack />;
}
const mapStateToProps = (state) => ({
isLoggedIn: state.auth.isLoggedIn,
});
export default connect(mapStateToProps, { autoLogin })(Root);