Skip to content

Instantly share code, notes, and snippets.

@emilong
Created May 29, 2017 03:07
Show Gist options
  • Save emilong/621931fdfe13b1857790afa0ebc766c4 to your computer and use it in GitHub Desktop.
Save emilong/621931fdfe13b1857790afa0ebc766c4 to your computer and use it in GitHub Desktop.
Fetching data to component state
const brandUrl = brand =>
`https://makeup-api.herokuapp.com/api/v1/products.json?brand=${brand.toLowerCase()}`;
export default class Brand extends Component {
fetchBrand = (brand = this.props.match.params.brand) => {
fetch(brandUrl(brand))
.then(response => response.json())
.then(products => this.setState({ products }));
};
...
render() {
// render from state
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment