I'm trying myself in react and trying to make a simple application, which will display articles from the Hacker News. I have already made the first call to their API
componentDidMount() {
fetch('https://hacker-news.firebaseio.com/v0/jobstories.json?print=pretty')
.then(res => res.json())
.then(articles => {
this.setState({articles})
})
}
As the response, it returns an array of the articles IDs. To get detailed information for every single article I need to iterate the array I get and to make a second request for every article ID which has to look like
fetch(`https://hacker-news.firebaseio.com/v0/item/{id_from_the_array}`)
And I faced the problem because I have no idea how to implement it in a correct way.. Could someone please advice me?
forloop? Or even better aforeachloopfetch(...item/${id...with a$)constructor() { super(); this.state = { articles: null } } componentDidMount() { fetch('https://hacker-news.firebaseio.com/v0/askstories.json?print=pretty') .then(res => res.json()) .then(articles => { this.setState({articles}) }) }