Created
October 18, 2016 14:29
-
-
Save chrislaughlin/93f47c50f63f0394159c4c7d1ddf5476 to your computer and use it in GitHub Desktop.
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
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