Skip to content

Instantly share code, notes, and snippets.

@karlbright
Created April 29, 2015 14:45
Show Gist options
  • Save karlbright/663849826406bc0a2966 to your computer and use it in GitHub Desktop.
Save karlbright/663849826406bc0a2966 to your computer and use it in GitHub Desktop.
import React from 'react'
import {Link, State} from 'react-router'
import Superagent from 'superagent'
// <RepoDetail name='collabtracks' author='karlbright' />
class RepoDetail extends React.Component {
componentWillMount() {
this.loadDetails(this.props.author, this.props.name);
}
componentWillReceiveProps() {
this.loadDetails(this.props.author, this.props.name);
}
loadDetails(author, name) {
Superagent.get(`https://api.github.com/repos/${author}/${name}`)
.send()
.end((error, response) => {
this.setState({ repo: response.body });
});
}
render() {
if(!this.state.repo) return null;
return (
<div className="repo-detail">
<h1>Repository: {this.state.repo.name}</h1>
</div>
)
}
}
export default RepoDetail;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment