File tree Expand file tree Collapse file tree 3 files changed +31
-2
lines changed Expand file tree Collapse file tree 3 files changed +31
-2
lines changed Original file line number Diff line number Diff line change 1+ import { useState } from "react" ;
2+ import axios from "axios" ;
3+ import { RepositoryData } from "../types/github" ;
4+
5+ export const useFetchGitHub = ( ) : RepositoryData => {
6+ const [ data , setData ] = useState < RepositoryData > ( {
7+ forks : "0" ,
8+ stargazers : "0" ,
9+ } ) ;
10+
11+ axios
12+ . get ( "https://api.github.com/repos/0l1v3rr/github-readme-tech-stack" )
13+ . then ( ( res ) => {
14+ const rd : any = res . data ;
15+ setData ( {
16+ stargazers : rd . stargazers_count ,
17+ forks : rd . forks_count ,
18+ } ) ;
19+ } ) ;
20+
21+ return data ;
22+ } ;
Original file line number Diff line number Diff line change @@ -2,8 +2,11 @@ import ButtonLink from "../components/buttons/ButtonLink";
22import Title from "../components/repo/Title" ;
33import { AiOutlineStar , AiOutlineGithub } from "react-icons/ai" ;
44import { BiGitRepoForked } from "react-icons/bi" ;
5+ import { useFetchGitHub } from "../hooks/useFetchGitHub" ;
56
67const Header = ( ) => {
8+ const ghStats = useFetchGitHub ( ) ;
9+
710 return (
811 < header className = "flex flex-col justify-center items-center w-full mt-5" >
912 < Title repoName = "github-readme-tech-stack" username = "0l1v3rr" />
@@ -19,14 +22,14 @@ const Header = () => {
1922 < ButtonLink
2023 link = "https://github.com/0l1v3rr/github-readme-tech-stack/network/members"
2124 icon = { BiGitRepoForked }
22- num = { 6 }
25+ num = { Number ( ghStats . forks ) }
2326 text = "Fork"
2427 />
2528
2629 < ButtonLink
2730 link = "https://github.com/0l1v3rr/github-readme-tech-stack/stargazers"
2831 icon = { AiOutlineStar }
29- num = { 37 }
32+ num = { Number ( ghStats . stargazers ) }
3033 text = "Star"
3134 />
3235 </ div >
Original file line number Diff line number Diff line change 1+ export interface RepositoryData {
2+ stargazers : string ;
3+ forks : string ;
4+ }
You can’t perform that action at this time.
0 commit comments