-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.jsx
60 lines (56 loc) · 1.37 KB
/
App.jsx
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
import React, { useState, useEffect } from "react";
import { StatusBar } from "expo-status-bar";
import { StyleSheet, Text, View } from "react-native";
import useApiRequest from "./hooks/useApiRequest";
const config = {
headers: {
/* Place headers here E.g.
accessKey:
"veryLongAPIkey",
*/
"Content-Type": "application/json",
}
};
export default function App() {
const { data, error, isLoaded } = useApiRequest(
"https://api.dictionaryapi.dev/api/v2/entries/en/plinth",
config
);
console.log(data);
if (error !== null) {
return (
<View style={styles.container}>
<Text style={styles.header}>Oops!</Text>
<Text>{error.message}</Text>
<StatusBar style="auto" />
</View>
);
}
if (data.length == 0) {
return (
<View style={styles.container}>
<Text style={styles.header}>Loading...</Text>
<StatusBar style="auto" />
</View>
);
}
const meaning = data[0].meanings[0].definitions[0].definition;
return (
<View style={styles.container}>
<Text style={styles.header}>Word definition:</Text>
<Text>{meaning}</Text>
<StatusBar style="auto" />
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#fff",
alignItems: "center",
justifyContent: "center",
},
header: {
fontSize: 24,
},
});