No Description

fetchData.js 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <<<<<<< HEAD
  2. import * from styles
  3. =======
  4. import * from styles;
  5. >>>>>>> Prawject_UserSt1
  6. import DropDownPicker from 'react-native-dropdown-picker';
  7. import React, {useState, useEffect} from 'react';
  8. //ALL REQUIRED TO GET DATA
  9. DropDownPicker.setListMode("SCROLLVIEW")
  10. //data parsing goes here
  11. function getInfo(information){
  12. //console.log(information[6])
  13. if(!information)
  14. {Alert.alert("Please try again later! Error retriving data")}
  15. else
  16. {return information}
  17. }
  18. //data display
  19. class DataButton extends React.Component{
  20. state = {
  21. click: false
  22. }
  23. pullData = () => {createQuery(pueblo, table); information = loadDoc(query); this.setState({click: true})}
  24. render() {
  25. return(
  26. <View>
  27. <Button
  28. onPress = {this.pullData}
  29. title = "Fetch Data"
  30. color = "black"
  31. />
  32. <Text style={styles.sub}>{getInfo()}</Text>
  33. </View>
  34. );}
  35. }
  36. function createQuery(pueblo, table) {
  37. const queryBase = "https://api.census.gov/data/2020/acs/acs5/profile?get=group"
  38. const queryEnd = "&in=state:72"
  39. console.log("fetching data")
  40. var query = queryBase + "(" + table + ")&for=county:" + pueblo + queryEnd
  41. if(pueblo && table)
  42. {return query}
  43. else
  44. {Alert.alert("Please fill every parameter before calling!")}
  45. }
  46. function loadDoc(query) {
  47. var xhttp = new XMLHttpRequest();
  48. xhttp.onreadystatechange = function() {
  49. if (this.readyState == 4 && this.status == 200) {
  50. var information = this.responseText;
  51. return information
  52. }
  53. };
  54. xhttp.open("GET", query, true);
  55. xhttp.send();
  56. }