No Description

MocionScreen.js 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import React, { useEffect, useState } from 'react';
  2. import { ActivityIndicator, FlatList, Text, TouchableOpacity, View } from 'react-native';
  3. import { globalStyles } from '../styles/global';
  4. export default App = () => {
  5. const [isLoading, setLoading] = useState(true);
  6. const [Description, setDescription] = useState([]); // this is looking for 'Description' and it's content
  7. const [Mocion, setMocion] = useState([]); // this is looking for 'Mocion' and it's content
  8. const [PIN, setPIN] = useState([]); // this is looking for 'PIN' 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://10.190.1.140:5000/send?PIN=121071'); // 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. setPIN(json.PIN);
  18. } catch (error) {
  19. console.error(error);
  20. } finally {
  21. setLoading(false); // once found the loading icon will be replaced with the content of the json
  22. }
  23. }
  24. useEffect(() => {
  25. getMociones();
  26. }, []);
  27. // this is for displaying the mocion on the screen
  28. return (
  29. <View style={{ flex: 1, padding: 24 }}>
  30. <Text>{Mocion}</Text>
  31. <Text>{Description}</Text>
  32. </View>
  33. );
  34. };