No Description

App.js 1.1KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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 [data, setData] = useState([]);
  6. // this connects us to the API and fetches the json file with the mociones
  7. const getMociones = async () => {
  8. try {
  9. const response = await fetch('http://127.0.0.1:5000/send?PIN=121071');
  10. const json = await response.json();
  11. setData(json.Description);
  12. } catch (error) {
  13. console.error(error);
  14. } finally {
  15. setLoading(false);
  16. }
  17. }
  18. useEffect(() => {
  19. getMociones();
  20. }, []);
  21. // here we want to display each mocion in a flatlist
  22. // it's supposed to be like buttons. Once clicked it would let you vote inside
  23. return (
  24. <View style={{ flex: 1, padding: 24 }}>
  25. {isLoading ? <ActivityIndicator/> : (
  26. <FlatList
  27. data={data}
  28. keyExtractor={({ id }, index) => id}
  29. renderItem={({ item }) => (
  30. <Text>{data}</Text>
  31. )}
  32. />
  33. )}
  34. </View>
  35. );
  36. };