No Description

Lista.js 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import React, { useEffect, useState } from "react";
  2. import {
  3. ActivityIndicator,
  4. FlatList,
  5. View,
  6. Text,
  7. StyleSheet,
  8. TouchableOpacity,
  9. } from "react-native";
  10. const Lista = () => {
  11. const [isLoading, setLoading] = useState(true);
  12. const [data, setData] = useState([]);
  13. const getComplaints = async () => {
  14. try {
  15. const response = await fetch("http://192.168.7.178:5001/complaints/all");
  16. const json = await response.json();
  17. setData(json.Complaints);
  18. } catch (error) {
  19. console.error(error);
  20. } finally {
  21. setLoading(false);
  22. }
  23. };
  24. useEffect(() => {
  25. getComplaints();
  26. }, []);
  27. return (
  28. <View style={{ flex: 1, padding: 24 }}>
  29. {isLoading ? (
  30. <ActivityIndicator />
  31. ) : (
  32. <FlatList
  33. data={data}
  34. keyExtractor={({ id }, index) => id}
  35. renderItem={({ item }) => (
  36. <Text style={{ padding: 8 }}>
  37. ID:{item.id}, Tipo de denuncia: {item.complaint_type}, Hecha por:{" "}
  38. {item.name}, en el lugar: {item.place}, descripcion del problema:{" "}
  39. {item.complaint_description}, estatus:{"En espera"}
  40. </Text>
  41. )}
  42. />
  43. )}
  44. </View>
  45. );
  46. };
  47. export default Lista;