-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
69 lines (61 loc) · 1.39 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import React, {useState, useEffect} from 'react';
import {
SafeAreaView,
ScrollView,
StatusBar,
StyleSheet,
useColorScheme,
View,
} from 'react-native';
import Axios from 'axios';
import {Button, Text} from 'native-base';
import User from './components/User';
// const key = 'some random key with 123';
// const URL = `https://randomuser.me/api/${key}/params`
const App = () => {
const [details, setDetails] = useState(null);
const fetchDetails = async () => {
try {
const {data} = await Axios.get('https://randomuser.me/api/');
const details = data.results[0];
console.log(details);
setDetails(details);
} catch (error) {
console.log(error);
}
};
useEffect(() => {
fetchDetails();
}, []);
if (!details) {
return (
<View style={styles.container}>
<Text>Loading.....</Text>
</View>
);
} else {
return (
<View style={styles.container}>
<View>
<User details={details} />
<Button rounded style={styles.button} onPress={() => fetchDetails()}>
<Text>New User</Text>
</Button>
</View>
</View>
);
}
};
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#222831',
},
button: {
marginTop: 30,
paddingHorizontal: 30,
},
});
export default App;