我无法从 Twitch API 映射评论/结果。当我尝试映射时遇到 TypeError,并且从 API 存储的结果上限为 60 条记录,并且我找不到保持映射的方法。
下面是我处理 API 调用和映射的组件...
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>
);
}
}
我在控制台中得到以下结果,这很好,但是当我尝试映射时,我收到错误“TypeError:hits.map 不是函数”。
此外,我从 Twitch API 获得的结果总是上限为 60 条记录,然后在底部有一个“_next”字段。我似乎找不到继续映射超过 60 标记的记录的方法。
任何帮助将不胜感激。谢谢!