SHARE
TWEET

Untitled

a guest Nov 15th, 2017 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. componentWillMount() {
  2.     fetch(countries)
  3.       .then(data => data.json())
  4.       .then(data => {
  5.          // call fetch cities by constructing a "dummy" event.
  6.          const first = json.results[0]
  7.          const evt = {target: {value: first.code} }
  8.          fetchCities(evt)
  9.          // pass the data on
  10.          return data
  11.       })
  12.       .then(json => this.setState({ countries: json.results}))
  13.   }
  14.  
  15.  
  16.  
  17.   fetchCities = (evt) => {
  18.     const countryCode = evt.target.value
  19.     fetch(cities + "?country=" + countryCode)
  20.     .then(data => data.json())
  21.     .then(cities => {
  22.       // construct a "dummy event and then call fetchAir
  23.       const first = cities.results[0]
  24.       const evt = {target: {value: first.city}}
  25.       fetchAir(evt)
  26.       // pass the data on
  27.       return cities
  28.     })
  29.     .then(cities => this.setState({cities: cities.results}))        
  30.                    
  31.   }
  32.  
  33.  
  34.  
  35.   fetchAir = (evt) => {
  36.       const Air = evt.target.value
  37.       fetch(latest +"?city="+ Air)
  38.       .then(data => data.json())
  39.       .then(data => this.setState({latest: data.results}))
  40.   }
RAW Paste Data
Top