Я работаю, реагирую на редукцию, чтобы получить github API. На утешение
total_count его отображение не определено. Однако я могу отобразить
avatar_url, логин, html_url.
Ниже приведен код:
class SearchResults extends Component {
renderList(user) {
if (!user) {
return <div class="panel">No User Available</div>
}
return user.items.map(item => {
// console.log(item);
return <SearchItem
key={item.id}
name={item.login}
src={item.avatar_url}
alt={item.login}
profileLink={item.html_url}
/>
})
}
userCount() {
let count = this.props.users.total_count;
console.log(this.props.users.total_count);
return <div className="panel"> {count} </div>;
}
render() {
return (
<div className="user-list">
{
this.userCount()
}
{
this.props.users.map(this.renderList)
}
</div>
)
}
}
const mapStateToProps = ({ users }) => {
return {
users
}
}
export default connect(mapStateToProps)(SearchResults);
Вот пример Github API:
{
"total_count": 36252,
"incomplete_results": ложь,
"Предметы": [
{
"логин": "абхи",
"id": 784144,
"node_id": "MDQ6VXNlcjc4NDE0NA ==",
"avatar_url": "https://avatars2.githubusercontent.com/u/784144?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/abhi",
"html_url": "https://github.com/abhi",
"follow__url": "https://api.github.com/users/abhi/followers",
"follow_url": "https://api.github.com/users/abhi/following{/other_user}",
"gists_url": "https://api.github.com/users/abhi/gists{/gist_id}",
"starred_url": "https://api.github.com/users/abhi/starred{/owner}{/repo}",
"subscription_url": "https://api.github.com/users/abhi/subscriptions",
"organization_url": "https://api.github.com/users/abhi/orgs",
"repos_url": "https://api.github.com/users/abhi/repos",
"events_url": "https://api.github.com/users/abhi/events{/privacy}",
"receive_events_url": "https://api.github.com/users/abhi/received_events",
"type": "User",
"site_admin": ложь,
"оценка": 123,63206
},
{...},
{..},
}