Skip to content

Instantly share code, notes, and snippets.

@zachfedor
Created June 5, 2017 21:05
Show Gist options
  • Save zachfedor/dd3711573de64dffcfe7ffaa6213c573 to your computer and use it in GitHub Desktop.
Save zachfedor/dd3711573de64dffcfe7ffaa6213c573 to your computer and use it in GitHub Desktop.
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