-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
75 lines (63 loc) · 2.02 KB
/
App.js
File metadata and controls
75 lines (63 loc) · 2.02 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import React, { useState, useEffect } from 'react';
import type {Node} from 'react';
import {
StyleSheet,
Text,
View,
Button
} from 'react-native';
import { NavigationContainer } from '@react-navigation/native';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import AppContext from './components/AppContext';
import HomeScreen from './components/HomeScreen';
import UserList from './components/UserList';
import SingleUser from './components/SingleUser';
import ErrorComponent from './components/ErrorComponent';
const App: () => Node = () => {
const [globalUsers, setGlobalUsers] = useState(false);
const [isOrangeMode, setIsOrangeMode] = useState(false);
const addIndexToData = (data) => data.map((x, i) => { x.id = i + 1; return x; });
const updateGlobalUsers = (data) => {
addIndexToData(data);
setGlobalUsers(data);
};
const getSingleUser = (id) => {
return globalUsers.find(o => o.id === id)
};
const globalContext = {
users: globalUsers,
orangeMode: isOrangeMode,
setIsOrangeMode,
setGlobalUsers,
getSingleUser,
updateGlobalUsers
};
const Stack = createNativeStackNavigator();
const fetchData = async () => {
const resp = await fetch('https://randomuser.me/api/?results=200&exc=id&nat=gb');
const data = await resp.json();
if (data.results) {
updateGlobalUsers(data.results);
}
};
useEffect(() => {
fetchData();
}, []);
return (
<NavigationContainer>
<AppContext.Provider value={globalContext}>
<Stack.Navigator>
<Stack.Screen
name='Home'
component={HomeScreen}
options={{ title: 'Visionmate Recuitment App' }}
/>
<Stack.Screen name='UserList' component={UserList} />
<Stack.Screen name='SingleUser' component={SingleUser} />
<Stack.Screen name='Error' component={ErrorComponent} />
</Stack.Navigator>
</AppContext.Provider>
</NavigationContainer>
);
};
export default App;