Skip to content

Commit

Permalink
moved release hooks in correct folder and implements useForks
Browse files Browse the repository at this point in the history
  • Loading branch information
bdbch committed Jul 20, 2019
1 parent 0d5d239 commit ebc494a
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 2 deletions.
23 changes: 23 additions & 0 deletions docs/components/Forks.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React from "react";
import { useForks } from "../../src";

const Forks = () => {
const { forks, loading, error } = useForks("facebook", "react");

return (
<div>
<h1>Forks by repo</h1>
{loading && <div>Loading forks from Github</div>}
{error && <div>{error}</div>}
{forks &&
forks.length > 0 &&
forks.map(fork => (
<div key={fork.id}>
<h4>{fork.full_name}</h4>
</div>
))}
</div>
);
};

export default Forks;
3 changes: 3 additions & 0 deletions docs/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Branches from "./components/Branches";
import Branch from "./components/Branch";
import LatestRelease from "./components/LatestRelease";
import TaggedRelease from "./components/TaggedRelease";
import Forks from "./components/Forks";

function App() {
return (
Expand All @@ -22,6 +23,8 @@ function App() {
<hr />
<TaggedRelease />
<hr />
<Forks />
<hr />
</div>
);
}
Expand Down
7 changes: 5 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import useRepos from './lib/useRepos'
import useUser from './lib/useUser'
import useBranches from './lib/branch/useBranches'
import useBranch from './lib/branch/useBranch'
import useLatestRelease from './lib/repository/useLatestRelease'
import useTaggedRelease from './lib/repository/useTaggedRelease'
import useLatestRelease from './lib/release/useLatestRelease'
import useTaggedRelease from './lib/release/useTaggedRelease'
import useForks from './lib/repository/useForks'

export {
useRepos,
Expand All @@ -12,6 +13,7 @@ export {
useBranch,
useLatestRelease,
useTaggedRelease,
useForks,
}

export default {
Expand All @@ -21,4 +23,5 @@ export default {
useBranch,
useLatestRelease,
useTaggedRelease,
useForks,
}
File renamed without changes.
File renamed without changes.
35 changes: 35 additions & 0 deletions src/lib/repository/useForks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import {
useState,
useEffect
} from 'react'

export default function useForks(owner, repo) {
const [forks, setForks] = useState([])
const [loading, setLoading] = useState(false)
const [error, setError] = useState(null)

useEffect(() => {
if (repo && repo.length > 0 && owner && owner.length) {
setLoading(true)
setError(null)
fetch(`https://api.github.com/repos/${owner}/${repo}/forks`)
.then(res => res.json())
.then(data => {
setLoading(false)
setForks(data)
setError(null)
})
.catch(e => {
setLoading(false)
setForks([])
setError(e)
})
}
}, [owner, repo])

return {
forks,
loading,
error
}
}

0 comments on commit ebc494a

Please sign in to comment.