Skip to content

Instantly share code, notes, and snippets.

@chrislaughlin
Created October 18, 2016 14:29
Show Gist options
  • Save chrislaughlin/93f47c50f63f0394159c4c7d1ddf5476 to your computer and use it in GitHub Desktop.
Save chrislaughlin/93f47c50f63f0394159c4c7d1ddf5476 to your computer and use it in GitHub Desktop.
componentDidMount() {
axios.get('https://hacker-news.firebaseio.com/v0/topstories.json?print=pretty')
.then(response => {
let posts = [];
const lastPostIndex = response.data.length - 1;
for (var i = 0; i < response.data.length; i++) {
axios.get('https://hacker-news.firebaseio.com/v0/item/' + response.data[i] + '.json?print=pretty')
.then(post => {
posts.push(post.data);
if (i === lastPostIndex) {
this.setState({posts});
}
});
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment