-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
40 lines (32 loc) · 993 Bytes
/
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
import React, { useState, useEffect } from 'react';
import auth from '@react-native-firebase/auth';
import MainScreen from "./src/Main/index";
import SignScreen from "./src/Sign/sign";
export default function App() {
// Set an initializing state whilst Firebase connects
const [initializing, setInitializing] = useState(true);
const [user, setUser] = useState();
// Check if user open screen on SignScreen or not
const [disconnected, setDisconnected] = useState(false)
// Handle user state changes
function onAuthStateChanged(user) {
setUser(user);
if(!user){
setDisconnected(true);
}
if (initializing) setInitializing(false);
}
useEffect(() => {
const subscriber = auth().onAuthStateChanged(onAuthStateChanged);
return subscriber; // unsubscribe on unmount
}, []);
if (initializing) return null;
if (disconnected) {
return (
<SignScreen setDisconnected={setDisconnected}/>
);
}
return (
<MainScreen/>
);
}