react.js-12-promise

前端之家收集整理的这篇文章主要介绍了react.js-12-promise前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

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 );

    原文链接:https://www.f2er.com/react/307069.html

    猜你在找的React相关文章