12345678910111213141516171819202122232425262728293031323334353637383940 |
- import React, { useEffect, useState } from 'react';
- import { ActivityIndicator, FlatList, Text, View } from 'react-native';
-
- export default App = () => {
- const [isLoading, setLoading] = useState(true);
- const [data, setData] = useState([]);
-
- // this connects us to the API and fetches the json file with the mociones
- const getMociones = async () => {
- try {
- const response = await fetch('http://127.0.0.1:5000/send?PIN=121071');
- const json = await response.json();
- setData(json.Description);
- } catch (error) {
- console.error(error);
- } finally {
- setLoading(false);
- }
- }
-
- useEffect(() => {
- getMociones();
- }, []);
-
- // here we want to display each mocion in a flatlist
- // it's supposed to be like buttons. Once clicked it would let you vote inside
- return (
- <View style={{ flex: 1, padding: 24 }}>
- {isLoading ? <ActivityIndicator/> : (
- <FlatList
- data={data}
- keyExtractor={({ id }, index) => id}
- renderItem={({ item }) => (
- <Text>{data}</Text>
- )}
- />
- )}
- </View>
- );
- };
|