Нема описа

MocionScreen.js 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import React, { useEffect, useState } from 'react';
  2. import { ActivityIndicator, FlatList, Text, View } from 'react-native';
  3. export default App = () => {
  4. const [isLoading, setLoading] = useState(true);
  5. const [Description, setDescription] = useState([]); // this is looking for 'Description' and it's content
  6. const [Mocion, setMocion] = useState([]); // this is looking for 'Mocion' and it's content
  7. const [PIN, setPIN] = useState([]); // this is looking for 'PIN' and it's content
  8. // this connects us to the API and fetches the json file with the mociones
  9. const getMociones = async () => {
  10. try {
  11. const response = await fetch('http://10.190.1.140:5000/send?PIN=121071'); // connection to the website
  12. const json = await response.json();
  13. // setting the content of each category
  14. setMocion(json.Mocion);
  15. setDescription(json.Description);
  16. setPIN(json.PIN);
  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. // here we want to display each mocion in a flatlist
  27. // it's supposed to be like buttons. Once clicked it would let you vote inside
  28. return (
  29. <View style={{ flex: 1, padding: 24 }}>
  30. <Text>{Mocion}</Text>
  31. <Text>{Description}</Text>
  32. <Text>{PIN}</Text>
  33. </View>
  34. );
  35. };