-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
80 lines (63 loc) · 1.82 KB
/
Copy pathApp.js
File metadata and controls
80 lines (63 loc) · 1.82 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
import React, { useState, useEffect } from 'react';
import { Text, View } from 'react-native';
const API_URL = 'https://4s2cj3p44k.execute-api.us-east-1.amazonaws.com/beta'
// export default function App() {
// const [data, setData] = useState(null);
// const [error, setError] = useState(null);
//
// useEffect(() => {
// fetchData();
// }, []);
//
// const fetchData = async () => {
// try {
// const response = await fetch(API_URL);
// const json = await response.json();
// setData(json);
// } catch (error) {
// setError(error);
// }
// };
//
// return (
// <View>
// {data ? (
// <View>
// <Text>ID: {data.prompt}</Text>
// <Text>Title: {data.generated_text}</Text>
// </View>
// ) : (
// <Text>Loading...</Text>
// )}
// {error && <Text>Error: {error.message}</Text>}
// </View>
// );
// }
// import React, { useState, useEffect } from 'react';
// import { View, Text } from 'react-native';
import axios from 'axios';
const Api = () => {
const [data, setData] = useState(null);
useEffect(() => {
const fetchData = async () => {
const result = await axios.post('https://4s2cj3p44k.execute-api.us-east-1.amazonaws.com/beta', {}, {
timeout: 30000,
headers: {
'x-api-key': ''
}
});
setData(result.data.body);
};
fetchData();
}, []);
return (
<View>
{data ? (
<Text>{data}</Text>
) : (
<Text>Loading...</Text>
)}
</View>
);
};
export default Api;