Sin descripción

MocionScreen.js 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import React, { useEffect, useState } from 'react';
  2. import { ActivityIndicator, Button, FlatList, Text, TouchableOpacity, View } from 'react-native';
  3. import { globalStyles } from '../styles/global';
  4. import Card from '../shared/card';
  5. export default App = () => {
  6. const [isLoading, setLoading] = useState(true);
  7. const [Description, setDescription] = useState([]); // this is looking for 'Description' and it's content
  8. const [Mocion, setMocion] = useState([]); // this is looking for 'Mocion' and it's content
  9. // this connects us to the API and fetches the json file with the mociones
  10. const getMociones = async () => {
  11. try {
  12. const response = await fetch('http://192.168.1.200:5000/send?PIN=613382'); // connection to the website
  13. const json = await response.json();
  14. // setting the content of each category
  15. setMocion(json.Mocion);
  16. setDescription(json.Description);
  17. } catch (error) {
  18. console.error(error);
  19. } finally {
  20. setLoading(false); // once found the loading icon will be replaced with the content of the json
  21. }
  22. }
  23. useEffect(() => {
  24. getMociones();
  25. }, []);
  26. // this is for displaying the mocion on the screen
  27. return (
  28. <View style={{ flex: 1, padding: 24 }}>
  29. <Text>{Mocion}</Text>
  30. <Text>{Description}</Text>
  31. <Button title= 'A favor' color={'#e81b39'} />
  32. </View>
  33. );
  34. };