"use client"; import MinecraftButton from "@/components/minecraft-button"; import { Skeleton } from "@/components/ui/skeleton"; import { StarIcon } from "@heroicons/react/24/outline"; import Link from "next/link"; import { Dispatch, ReactElement, SetStateAction, Suspense, useEffect, useState, } from "react"; /** * The button to display the amount * of stars the GitHub repository has. * * @returns the component jsx */ const GitHubStarButton = (): ReactElement => { const [stars, setStars]: [ number | undefined, Dispatch> ] = useState(undefined); // The stars of the repository useEffect(() => { const fetchStars = async (): Promise => { const response: Response = await fetch( "https://api.github.com/repos/Rainnny7/RESTfulMC", { next: { revalidate: 300 } } // Revalidate every 5 minutes ); const json: any = await response.json(); // Get the JSON response setStars(json.stargazers_count); // Set the stars }; if (stars === undefined) { fetchStars(); // Fetch the stars } }, [stars]); return ( {/* Star Count */} } > {stars || 0} Star on GitHub ); }; export default GitHubStarButton;