Açıklama Yok

MocionScreen.js 1.5KB

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