切换主题,更新busuanzi

This commit is contained in:
tangly
2022-11-08 13:00:16 +08:00
parent 8b5ecdb35f
commit a27413df10

View File

@@ -1,10 +1,15 @@
import busuanzi from '@/lib/busuanzi'
import { useRouter } from 'next/router'
import { useEffect } from 'react'
import { useGlobal } from '@/lib/global'
// import { useRouter } from 'next/router'
import React from 'react'
export default function Busuanzi () {
const { theme } = useGlobal()
const router = useRouter()
useEffect(() => {
// 切换文章时更新
React.useEffect(() => {
const busuanziRouteChange = url => {
busuanzi.fetch()
}
@@ -13,5 +18,12 @@ export default function Busuanzi () {
router.events.off('routeChangeComplete', busuanziRouteChange)
}
}, [router.events])
// 更换主题时更新
React.useEffect(() => {
if (theme) {
busuanzi.fetch()
}
})
return null
}