-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fetch our own stars! #28
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const React = require('react') | ||
|
||
const script = ` | ||
void async function() { | ||
const response = await fetch('https://api.github.com/repos/isomorphic-git/isomorphic-git', { | ||
headers: { accept: 'application/vnd.github.v3+json' } | ||
}) | ||
const data = await response.json() | ||
document.querySelector('#gitHubStars').textContent = '(' + data.stargazers_count + ' stars)' | ||
}() | ||
` | ||
|
||
class GitHubStarButton extends React.Component { | ||
render() { | ||
// "Server-side" rendered, so `componentDidMount` wouldn't be called | ||
return ( | ||
<div> | ||
<a href="https://github.com/isomorphic-git/isomorphic-git">GitHub <span id="gitHubStars" /></a> | ||
<script dangerouslySetInnerHTML={{ __html: script }} /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hahaha this is so not the "right" way to populate a React component, but I love it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm actually not sure if I understand this right, I just wasn't getting any invocations on |
||
</div> | ||
); | ||
} | ||
} | ||
|
||
module.exports = GitHubStarButton |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe ⭐ emoji instead of the word "stars"?