I am trying to build something with hacker news API but I have a problem though. To get the items displayed to the screen. The items I need I need to first call another endpoint. I called this endpoint and looped through it so I can pass the data from that endpoint to the items endpoint which I need to work but I am only getting one Item displayed. How can I further do this to get like 30 items all at once?
state={
hackernews: []
}
componentDidMount(){
Axios.get('/newstories.json')
.then(res => {
for(let i = 0; i<res.data.length; i++){
const newsID = res.data[i];
return Axios.get(`/item/${newsID}.json`)
}
})
.then(res=>{
const news = res.data
this.setState({hackernews: [...this.state.hackernews, news]})
})
}
The hackernews api link https://github.com/HackerNews/API