forked from ruanyf/react-demos
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
117 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<script src="../build/react.js"></script> | ||
<script src="../build/react-dom.js"></script> | ||
<script src="../build/browser.min.js"></script> | ||
<script src="../build/jquery.min.js"></script> | ||
</head> | ||
<body> | ||
<script type="text/babel"> | ||
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 <span>Loading...</span>; | ||
} | ||
else if (this.state.error !== null) { | ||
return <span>Error: {this.state.error.message}</span>; | ||
} | ||
else { | ||
var repos = this.state.data.items; | ||
var repoList = repos.map(function (repo) { | ||
return ( | ||
<li><a href={repo.html_url}>{repo.name}</a> ({repo.stargazers_count} stars) <br/> {repo.description}</li> | ||
); | ||
}); | ||
return ( | ||
<main> | ||
<h1>Most Popular JavaScript Projects in Github</h1> | ||
<ol>{repoList}</ol> | ||
</main> | ||
); | ||
} | ||
} | ||
}); | ||
|
||
ReactDOM.render( | ||
<RepoList promise={$.getJSON('https://api.github.com/search/repositories?q=javascript&sort=stars')} />, | ||
document.body | ||
); | ||
</script> | ||
</body> | ||
</html> |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.