Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

index.tsx 1.0KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. 'use client'
  2. import { useQuery } from '@tanstack/react-query'
  3. import type { FC } from 'react'
  4. import type { GithubRepo } from '@/models/common'
  5. import { RiLoader2Line } from '@remixicon/react'
  6. const defaultData = {
  7. stargazers_count: 110918,
  8. }
  9. const getStar = async () => {
  10. const res = await fetch('https://api.github.com/repos/langgenius/dify')
  11. if (!res.ok)
  12. throw new Error('Failed to fetch github star')
  13. return res.json()
  14. }
  15. const GithubStar: FC<{ className: string }> = (props) => {
  16. const { isFetching, isError, data } = useQuery<GithubRepo>({
  17. queryKey: ['github-star'],
  18. queryFn: getStar,
  19. enabled: process.env.NODE_ENV !== 'development',
  20. retry: false,
  21. placeholderData: defaultData,
  22. })
  23. if (isFetching)
  24. return <RiLoader2Line className='size-3 shrink-0 animate-spin text-text-tertiary' />
  25. if (isError)
  26. return <span {...props}>{defaultData.stargazers_count.toLocaleString()}</span>
  27. return <span {...props}>{data?.stargazers_count.toLocaleString()}</span>
  28. }
  29. export default GithubStar