重复请求处理

This commit is contained in:
tangly1024
2022-12-06 22:35:34 +08:00
parent a6d3dfe7c0
commit 23fe756f34
4 changed files with 15 additions and 25 deletions

View File

@@ -4,26 +4,23 @@ import { useGlobal } from '@/lib/global'
// import { useRouter } from 'next/router'
import React from 'react'
let path = ''
export default function Busuanzi () {
const { theme } = useGlobal()
const router = useRouter()
// 切换文章时更新
React.useEffect(() => {
const busuanziRouteChange = url => {
const Router = useRouter()
Router.events.on('routeChangeComplete', (url, option) => {
if (url !== path) {
path = url
busuanzi.fetch()
}
router.events.on('routeChangeComplete', busuanziRouteChange)
return () => {
router.events.off('routeChangeComplete', busuanziRouteChange)
}
}, [router.events])
})
// 更换主题时更新
React.useEffect(() => {
if (theme) {
busuanzi.fetch()
}
})
}, [theme])
return null
}