Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- componentWillMount() {
- fetch(countries)
- .then(data => data.json())
- .then(data => {
- // call fetch cities by constructing a "dummy" event.
- const first = json.results[0]
- const evt = {target: {value: first.code} }
- fetchCities(evt)
- // pass the data on
- return data
- })
- .then(json => this.setState({ countries: json.results}))
- }
- fetchCities = (evt) => {
- const countryCode = evt.target.value
- fetch(cities + "?country=" + countryCode)
- .then(data => data.json())
- .then(cities => {
- // construct a "dummy event and then call fetchAir
- const first = cities.results[0]
- const evt = {target: {value: first.city}}
- fetchAir(evt)
- // pass the data on
- return cities
- })
- .then(cities => this.setState({cities: cities.results}))
- }
- fetchAir = (evt) => {
- const Air = evt.target.value
- fetch(latest +"?city="+ Air)
- .then(data => data.json())
- .then(data => this.setState({latest: data.results}))
- }
Add Comment
Please, Sign In to add comment