Created
June 5, 2017 21:05
-
-
Save zachfedor/dd3711573de64dffcfe7ffaa6213c573 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
getCountries() { | |
fetch('/api/endpoint/countries').then((data) => { | |
this.setState({ countries: data }); | |
}) | |
} | |
getCities(country) { | |
fetch(`/api/endpoint/countries/${country}/cities`).then((data) => { | |
this.setState({ cities: data }); | |
}); | |
} | |
onCountryChange() { | |
this.getCities(this.state.country); | |
} | |
componentDidMount() { | |
this.getCountries(); | |
} | |
render() { | |
<form> | |
<select id="country"> | |
{this.state.countries.map((c) => ( | |
<option value={c}>{c}</option> | |
))} | |
</select> | |
<select id="cite"> | |
{this.state.cities.map((c) => ( | |
<option value={c}>{c}</option> | |
))} | |
</select> | |
</form> | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment