No Description

HomeScreen.js 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import { propertiesListToString } from "@expo/config-plugins/build/android/Properties";
  2. import React, { useEffect, useState }from "react";
  3. import { StyleSheet, View, Text, Button } from 'react-native';
  4. import { globalStyles } from "../styles/global";
  5. export default App = ({ navigation }) => {
  6. const [isLoading, setLoading] = useState(true);
  7. const [Description, setDescription] = useState([]); // this is looking for 'Description' and it's content
  8. const [Mocion, setMocion] = useState([]); // this is looking for 'Mocion' and it's content
  9. const [PIN, setPIN] = useState([]); // this is looking for 'PIN' and it's content
  10. // this connects us to the API and fetches the json file with the mociones
  11. const getMociones = async () => {
  12. try {
  13. const response = await fetch('http://10.190.1.140:5000/send?PIN=121071'); // connection to the website
  14. const json = await response.json();
  15. // setting the content of each category
  16. setMocion(json.Mocion);
  17. setDescription(json.Description);
  18. setPIN(json.PIN);
  19. } catch (error) {
  20. console.error(error);
  21. } finally {
  22. setLoading(false); // once found the loading icon will be replaced with the content of the json
  23. }
  24. }
  25. const pressHandler = () => {
  26. navigation.navigate('Mocion');
  27. }
  28. useEffect(() => {
  29. getMociones();
  30. }, []);
  31. return (
  32. <View style = {globalStyles.container}>
  33. <Text style = {globalStyles.tittleText}>Home Screen</Text>
  34. <Button title="go to pin page" onPress={pressHandler}/>
  35. </View>
  36. )
  37. }