-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.tsx
77 lines (72 loc) · 1.62 KB
/
App.tsx
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
76
77
import React, {useState} from 'react';
import {
Alert,
Pressable,
SafeAreaView,
StyleSheet,
Text,
View,
FlatList,
} from 'react-native';
function App(): React.JSX.Element {
const [headers, setHeaders] = useState({});
const sendRequest = async () => {
setHeaders({});
try {
const response = await fetch('https://ksk.by?route=api/fake');
const json = await response.json();
if (json?.success?.headers) {
setHeaders(json.success.headers);
}
console.log(json.success.headers);
} catch (e) {
Alert.alert('Не удалось выполнить запрос');
}
};
return (
<SafeAreaView style={styles.container}>
<View>
<Pressable style={styles.button} onPress={sendRequest}>
<Text style={styles.text}>Отправить запрос</Text>
</Pressable>
</View>
<View style={styles.response}>
{headers && (
<FlatList
data={Object.entries(headers)}
renderItem={({item}) => (
<Text style={styles.header}>{item.join(': ')}</Text>
)}
/>
)}
</View>
</SafeAreaView>
);
}
const styles = StyleSheet.create({
container: {
display: 'flex',
justifyContent: 'flex-start',
alignItems: 'center',
height: '100%',
},
button: {
padding: 10,
backgroundColor: 'tomato',
borderRadius: 5,
marginTop: 30,
},
text: {
color: 'white',
fontSize: 18,
},
response: {
width: '100%',
marginVertical: 30,
paddingHorizontal: 30,
},
header: {
marginTop: 10,
},
});
export default App;