-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
49 lines (40 loc) · 1.08 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
import React, { useState } from 'react';
import {
SafeAreaView,
ScrollView,
Text,
Button,
StatusBar,
} from 'react-native';
const App: () => React$Node = () => {
const [data, setData] = useState("No Result");
const makeRequest = async ()=> {
let response = await fetch("https://randomuser.me/api/");
try{
if (response.ok) {
let json = await response.json();
console.log("api response ",json.results);
setData(JSON.stringify(json.results, null, 4));
if(!json.results.length) {
alert("Random Data Empty");
}
} else {
alert("HTTP-Error: " + response.status);
}
} catch (e) {
alert("Unexpected error occur" + e);
}
};
return (
<>
<StatusBar barStyle="dark-content" />
<SafeAreaView>
<Button title={"Get Random User"} onPress={makeRequest}/>
<ScrollView style={{marginTop:20, paddingHorizontal :20}}>
<Text>{data}</Text>
</ScrollView>
</SafeAreaView>
</>
);
};
export default App;