-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathApp.js
More file actions
51 lines (46 loc) · 1.19 KB
/
App.js
File metadata and controls
51 lines (46 loc) · 1.19 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
import * as React from 'react';
import { StatusBar } from 'expo-status-bar';
import { ActivityIndicator, StyleSheet, Text, View, Button } from 'react-native';
const axios = require('axios').default;
export default function App() {
const [frases, setFrases] = React.useState([])
const [loading, setLoading] = React.useState(false)
function pegarAPI(){
setLoading(true);
axios.get("http://dog-api.kinduff.com/api/facts?number=5")
.then(function (resp){
setFrases(resp.data.facts);
setLoading(false);
})
.catch(function (err){
console.log(err);
})
}
return (
<View style={styles.container}>
{!loading ? <Button
title="Obtener frase"
onPress={() => pegarAPI()}
style={styles.boton}
/> : <ActivityIndicator/>}
{frases.length == 0 ? null :
<>
{frases.map((frase, index) => <Text key={index}>{frase}</Text>)}
</>
}
<StatusBar style="auto" />
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
boton: {
color: 'red',
margin: 20
}
});