File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import React from "react" ;
2+ import { useCollaborators } from "../../src" ;
3+
4+ const Forks = ( ) => {
5+ const { collaborators, loading, error } = useCollaborators (
6+ "facebook" ,
7+ "react"
8+ ) ;
9+
10+ return (
11+ < div >
12+ < h1 > Collaborators by repo</ h1 >
13+ { loading && < div > Loading collaborators from Github</ div > }
14+ { error && < div > { error } </ div > }
15+ { collaborators &&
16+ collaborators . length > 0 &&
17+ collaborators . map ( collaborator => (
18+ < div key = { collaborator . id } >
19+ < h4 > { collaborator . login } </ h4 >
20+ </ div >
21+ ) ) }
22+ </ div >
23+ ) ;
24+ } ;
25+
26+ export default Forks ;
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ import Branch from "./components/Branch";
77import LatestRelease from "./components/LatestRelease" ;
88import TaggedRelease from "./components/TaggedRelease" ;
99import Forks from "./components/Forks" ;
10+ import Collaborators from "./components/Collaborators" ;
1011
1112function App ( ) {
1213 return (
@@ -25,6 +26,8 @@ function App() {
2526 < hr />
2627 < Forks />
2728 < hr />
29+ < Collaborators />
30+ < hr />
2831 </ div >
2932 ) ;
3033}
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ import useBranch from './lib/branch/useBranch'
55import useLatestRelease from './lib/release/useLatestRelease'
66import useTaggedRelease from './lib/release/useTaggedRelease'
77import useForks from './lib/repository/useForks'
8+ import useCollaborators from './lib/repository/useCollaborators'
89
910export {
1011 useRepos ,
@@ -14,6 +15,7 @@ export {
1415 useLatestRelease ,
1516 useTaggedRelease ,
1617 useForks ,
18+ useCollaborators ,
1719}
1820
1921export default {
@@ -24,4 +26,5 @@ export default {
2426 useLatestRelease,
2527 useTaggedRelease,
2628 useForks,
29+ useCollaborators,
2730}
Original file line number Diff line number Diff line change 1+ import {
2+ useState ,
3+ useEffect
4+ } from 'react'
5+
6+ export default function useCollaborators ( owner , repo ) {
7+ const [ collaborators , setCollaborators ] = 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 } /collaborators` )
16+ . then ( res => res . json ( ) )
17+ . then ( data => {
18+ setLoading ( false )
19+ setCollaborators ( data )
20+ setError ( null )
21+ } )
22+ . catch ( e => {
23+ setLoading ( false )
24+ setCollaborators ( [ ] )
25+ setError ( e )
26+ } )
27+ }
28+ } , [ owner , repo ] )
29+
30+ return {
31+ collaborators,
32+ loading,
33+ error
34+ }
35+ }
You can’t perform that action at this time.
0 commit comments