No Description

index.tsx 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import React from 'react';
  2. import {useState,useEffect} from 'react';
  3. import {View,TextInput,StyleSheet,FlatList} from "react-native";
  4. import ProductItems from "../../ProductItems/ProductItem";
  5. import fetch_json from '../../../fetch_json';
  6. export default function HomeScreen() {
  7. const [jsonProductos, setProductos] = useState([]);
  8. const urlProductos = 'http://136.145.231.41/raices_api/api/inventario/read.php';
  9. /*
  10. const [query, setQuery] = useState('');
  11. const filter = (query: string) => {
  12. return jsonProductos.filter((item) =>
  13. item.producto.toLocaleLowerCase().includes(query.toLocaleLowerCase())
  14. );
  15. };
  16. async function fetch_() {
  17. try {
  18. const response = await fetch(urlProductos);
  19. const json = await response.json();
  20. if (query.length === 0) {
  21. console.log('empty');
  22. setProductos(json);
  23. }
  24. else {
  25. console.log(query);
  26. setProductos(json.filter((item) => item.producto.includes(query)));
  27. }
  28. } catch (error) {
  29. console.error(error);
  30. };
  31. }
  32. */
  33. useEffect(() => {
  34. fetch_json(urlProductos, setProductos);
  35. //fetch_();
  36. });
  37. const [jsonInsignias, setInsignias] = useState([]);
  38. const url = 'http://136.145.231.41/raices_api/api/nosotros/read.php?id=1';
  39. useEffect(() => {
  40. fetch_json(url, setInsignias);
  41. });
  42. return (
  43. <View style={styles.page}>
  44. {/*
  45. <TextInput
  46. placeholder="Hacer búsqueda..."
  47. onChangeText={(query) => {setQuery(query)}}
  48. />
  49. */}
  50. <FlatList
  51. data={jsonProductos}
  52. renderItem={({item}) => <ProductItems item={item} />}
  53. keyExtractor={(item, index) => item.id_producto}
  54. />
  55. </View>
  56. );
  57. };
  58. const styles = StyleSheet.create({
  59. page: {
  60. padding: 10,
  61. },
  62. });