From a27413df1042848df4dc6fef42afd0d9088168ca Mon Sep 17 00:00:00 2001 From: tangly Date: Tue, 8 Nov 2022 13:00:16 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=87=E6=8D=A2=E4=B8=BB=E9=A2=98,=E6=9B=B4?= =?UTF-8?q?=E6=96=B0busuanzi?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/Busuanzi.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/components/Busuanzi.js b/components/Busuanzi.js index a2456a75..12e592d8 100644 --- a/components/Busuanzi.js +++ b/components/Busuanzi.js @@ -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 }