Skip to content

Instantly share code, notes, and snippets.

@velotiotech
Last active January 13, 2021 05:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save velotiotech/c07643a963d0807f13c0e2168796969b to your computer and use it in GitHub Desktop.
Save velotiotech/c07643a963d0807f13c0e2168796969b to your computer and use it in GitHub Desktop.
import { useEffect, useState } from 'react';
import { useParams } from 'react-router-dom';
import { octokit } from './client';
function RepoDetails() {
const [repo, setRepo] = useState();
const { repo: repoName, owner } = useParams();
useEffect(() => {
octokit
.request('GET /repos/{owner}/{repo}', {
owner,
repo: repoName,
})
.then((data) => setRepo(data.data));
}, [repoName, owner]);
if (!repo) {
return <b>loading...</b>;
}
return (
<div className="repo-container">
<h1>{repo.full_name}</h1>
<p>Description: {repo.description}</p>
<ul>
<li><b>Forks:</b> {repo.forks}</li>
<li><b>Subscribers:</b> {repo.subscribers_count}</li>
<li><b>Watchers:</b> {repo.watchers}</li>
<li><b>License:</b> {repo.license.name}</li>
</ul>
</div>
);
}
export default RepoDetails;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment