Created
May 29, 2017 03:07
-
-
Save emilong/621931fdfe13b1857790afa0ebc766c4 to your computer and use it in GitHub Desktop.
Fetching data to component state
This file contains hidden or 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
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