I'm having trouble mapping comments / results from a Twitch API. I'm getting a TypeError when I try to map, and the results being stored from the API are capping at 60 records, and I cannot find a way to keep mapping past that.
Below is my Component that is handling the API call and mapping...
import React from 'react';
import ReactDOM from 'react-dom';
class Twitch extends React.Component{
constructor(props){
super(props);
this.state = {
cid : 'XXXXXXXXXXXXX',
api : 'https://api.twitch.tv/v5/videos/XXXXXXX/comments?client_id=' + this.state.cid,
hits : []
}
}
componentDidMount() {
fetch(this.state.api, {
method: 'get',
headers: {"Client-ID": this.state.cid}
})
.then((response) => response.text())
.then((responseText) => {
this.setState({hits : (JSON.parse(responseText))})
})
}
render(){
const { hits } = this.state;
console.log({hits});
return (
<ul>
{hits.map(hit =>
<li>
<p>{hit.content_type}</p>
</li>
)}
</ul>
);
}
}
I am getting the following result in my console which is good, but when I try to map I'm getting the error "TypeError: hits.map is not a function".
Also, the results i'm getting from the Twitch API always caps at 60 records and then has a '_next' field at the bottom. I can't seem to find a way to continue mapping records past the 60 mark.
Any help would be greatly appreciated. Thanks!