Skip to content

Commit ebc494a

Browse files
committed
moved release hooks in correct folder and implements useForks
1 parent 0d5d239 commit ebc494a

6 files changed

Lines changed: 66 additions & 2 deletions

File tree

docs/components/Forks.jsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import React from "react";
2+
import { useForks } from "../../src";
3+
4+
const Forks = () => {
5+
const { forks, loading, error } = useForks("facebook", "react");
6+
7+
return (
8+
<div>
9+
<h1>Forks by repo</h1>
10+
{loading && <div>Loading forks from Github</div>}
11+
{error && <div>{error}</div>}
12+
{forks &&
13+
forks.length > 0 &&
14+
forks.map(fork => (
15+
<div key={fork.id}>
16+
<h4>{fork.full_name}</h4>
17+
</div>
18+
))}
19+
</div>
20+
);
21+
};
22+
23+
export default Forks;

docs/example.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import Branches from "./components/Branches";
66
import Branch from "./components/Branch";
77
import LatestRelease from "./components/LatestRelease";
88
import TaggedRelease from "./components/TaggedRelease";
9+
import Forks from "./components/Forks";
910

1011
function App() {
1112
return (
@@ -22,6 +23,8 @@ function App() {
2223
<hr />
2324
<TaggedRelease />
2425
<hr />
26+
<Forks />
27+
<hr />
2528
</div>
2629
);
2730
}

src/index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ import useRepos from './lib/useRepos'
22
import useUser from './lib/useUser'
33
import useBranches from './lib/branch/useBranches'
44
import useBranch from './lib/branch/useBranch'
5-
import useLatestRelease from './lib/repository/useLatestRelease'
6-
import useTaggedRelease from './lib/repository/useTaggedRelease'
5+
import useLatestRelease from './lib/release/useLatestRelease'
6+
import useTaggedRelease from './lib/release/useTaggedRelease'
7+
import useForks from './lib/repository/useForks'
78

89
export {
910
useRepos,
@@ -12,6 +13,7 @@ export {
1213
useBranch,
1314
useLatestRelease,
1415
useTaggedRelease,
16+
useForks,
1517
}
1618

1719
export default {
@@ -21,4 +23,5 @@ export default {
2123
useBranch,
2224
useLatestRelease,
2325
useTaggedRelease,
26+
useForks,
2427
}

src/lib/repository/useForks.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import {
2+
useState,
3+
useEffect
4+
} from 'react'
5+
6+
export default function useForks(owner, repo) {
7+
const [forks, setForks] = useState([])
8+
const [loading, setLoading] = useState(false)
9+
const [error, setError] = useState(null)
10+
11+
useEffect(() => {
12+
if (repo && repo.length > 0 && owner && owner.length) {
13+
setLoading(true)
14+
setError(null)
15+
fetch(`https://api.github.com/repos/${owner}/${repo}/forks`)
16+
.then(res => res.json())
17+
.then(data => {
18+
setLoading(false)
19+
setForks(data)
20+
setError(null)
21+
})
22+
.catch(e => {
23+
setLoading(false)
24+
setForks([])
25+
setError(e)
26+
})
27+
}
28+
}, [owner, repo])
29+
30+
return {
31+
forks,
32+
loading,
33+
error
34+
}
35+
}

0 commit comments

Comments
 (0)