'use client'; import React, { useEffect, useState } from 'react'; import Link from 'next/link'; const GitHubStarButton: React.FC = () => { const [stars, setStars] = useState(null); useEffect(() => { fetch('https://api.github.com/repos/gitfromwildan/docubook') .then((res) => res.json()) .then((data) => { if (data.stargazers_count !== undefined) { setStars(data.stargazers_count); } }) .catch((error) => console.error('Failed to fetch stars:', error)); }, []); const formatStars = (count: number) => count >= 1000 ? `${(count / 1000).toFixed(1)}K` : `${count}`; return ( {stars !== null ? formatStars(stars) : '...'} ); }; export default GitHubStarButton;