您的位置:首页 > Web前端 > React

react.js-12-promise

2016-03-12 16:29 555 查看
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.name} ({repo.stargazers_count} stars)
{repo.description}

);

});

return (

Most Popular JavaScript Projects in Github

{repoList}

);

}

}

});

ReactDOM.render(
https://api.github.com/search/repositories?q=javascript&sort=stars‘)} />,

document.body

);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: