demo git地址:https://git.oschina.net/tomcode/reactdemo.git
var RepoList = React.createClass({
getInitialState: function() {
return {
loading: true,
error: null,
data: null
};
},
componentDidMount() {
this.props.promise.then(
value => this.setState({loading: false,data: value}),
error => this.setState({loading: false,error: error}));
},
render: function() {
if (this.state.loading) {
return Loading…;
}
else if (this.state.error !== null) {
return Error: {this.state.error.message};
}
else {
var repos = this.state.data.items;
var repoList = repos.map(function (repo) {
return (
{repo.description}
});
return (
Most Popular JavaScript Projects in Github
-
{repoList}
);
}
}
});
ReactDOM.render( https://api.github.com/search/repositories?q=javascript&sort=stars‘)} />,document.body );