-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.tsx
More file actions
56 lines (49 loc) · 1.5 KB
/
Copy pathApp.tsx
File metadata and controls
56 lines (49 loc) · 1.5 KB
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
53
54
55
56
import React, { useEffect, useState } from 'react';
import { StatusBar, View, ActivityIndicator } from 'react-native';
import { SafeAreaProvider } from 'react-native-safe-area-context';
import { Provider, useDispatch, useSelector } from 'react-redux';
import Toast from 'react-native-toast-message';
import { store, RootState } from './src/store';
import { RootNavigator } from './src/navigation/RootNavigator';
import { restoreUserSession } from './src/store/slices/authSlice';
import { AppDispatch } from './src/store';
function AppContent() {
const dispatch = useDispatch<AppDispatch>();
const { loading } = useSelector((state: RootState) => state.auth);
const [isReady, setIsReady] = useState(false);
useEffect(() => {
// Restore user session on app launch
const bootstrapAsync = async () => {
try {
await dispatch(restoreUserSession());
} catch (e) {
console.error(e);
} finally {
setIsReady(true);
}
};
bootstrapAsync();
}, [dispatch]);
if (!isReady) {
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<ActivityIndicator size="large" color="#FF6B6B" />
</View>
);
}
return (
<SafeAreaProvider>
<StatusBar barStyle="dark-content" backgroundColor="#fff" />
<RootNavigator isLoading={loading} />
<Toast />
</SafeAreaProvider>
);
}
function App() {
return (
<Provider store={store}>
<AppContent />
</Provider>
);
}
export default App;