Commit d1f63289 authored by Joel's avatar Joel

fix: server side render trigger github api rate limit

parent f369202c
'use client'
import React, { useEffect, useState } from 'react'
import { Github } from '@/app/components/base/icons/src/public/common' import { Github } from '@/app/components/base/icons/src/public/common'
import type { GithubRepo } from '@/models/common' import type { GithubRepo } from '@/models/common'
...@@ -10,18 +12,26 @@ const getStar = async () => { ...@@ -10,18 +12,26 @@ const getStar = async () => {
return res.json() return res.json()
} }
const GithubStar = async () => { const GithubStar = () => {
let githubRepo: GithubRepo = { stargazers_count: 0 } const [githubRepo, setGithubRepo] = useState<GithubRepo>({ stargazers_count: 6000 })
const [isFetched, setIsFetched] = useState(false)
useEffect(() => {
(async () => {
try {
if (process.env.NODE_ENV === 'development') if (process.env.NODE_ENV === 'development')
return null return
try { await setGithubRepo(await getStar())
githubRepo = await getStar() setIsFetched(true)
} }
catch (e) { catch (e) {
return null
} }
})()
}, [])
if (!isFetched)
return null
return ( return (
<a <a
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment