我尝试获取Github API以获取用户GitHub信息
componentDidMount() {
const { username } = this.props;
const { clientId, clientSecret, count, sort } = this.state;
fetch(
`http://api.github.com/users/${username}/repos?per_page=${count}&sort=${sort}&client_id=${clientId}&client_secret=${clientSecret}`
)
.then(res => res.json())
.then(data => {
if (this.refs.myRef) {
this.setState({ repos: data.conves });
}
})
.catch(err => console.log(err));
}
当我开始使用map()渲染时,我得到一个错误,指出map()无法正常工作!
const repoItems = repos.map(repo => (
<div>
<Link to={repo.html_url} className="text-info" target="_blank">
{repo.name}
</Link>
</div>
));