'use client' import type { FC } from 'react' import { useQuery } from '@tanstack/react-query' type GithubStarResponse = { repo: { stars: number } } const defaultData: GithubStarResponse = { repo: { stars: 110918 }, } const getStar = async () => { const res = await fetch('https://ungh.cc/repos/langgenius/dify') if (!res.ok) throw new Error('Failed to fetch github star') return res.json() } const GithubStar: FC<{ className: string }> = (props) => { const { isFetching, isError, data } = useQuery({ queryKey: ['github-star'], queryFn: getStar, retry: false, placeholderData: defaultData, }) if (isFetching) return if (isError) return {defaultData.repo.stars.toLocaleString()} return {data?.repo.stars.toLocaleString()} } export default GithubStar