From a6aa91d35a08baa258b6ead2633ad53a91283e76 Mon Sep 17 00:00:00 2001 From: hamster1963 <1410514192@qq.com> Date: Thu, 13 Feb 2025 14:56:56 +0800 Subject: [PATCH] fix: add locale dependency to component rendering effects --- components/Switch.tsx | 7 ++++--- components/TabSwitch.tsx | 5 +++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/components/Switch.tsx b/components/Switch.tsx index 863a87a..861c495 100644 --- a/components/Switch.tsx +++ b/components/Switch.tsx @@ -2,7 +2,7 @@ import getEnv from "@/lib/env-entry" import { cn } from "@/lib/utils" -import { useTranslations } from "next-intl" +import { useLocale, useTranslations } from "next-intl" import { createRef, useEffect, useRef, useState } from "react" export default function Switch({ @@ -19,6 +19,7 @@ export default function Switch({ const scrollRef = useRef(null) const tagRefs = useRef(allTag.map(() => createRef())) const t = useTranslations("ServerListClient") + const locale = useLocale() const [indicator, setIndicator] = useState<{ x: number; w: number }>({ x: 0, w: 0, @@ -58,7 +59,7 @@ export default function Switch({ w: currentTagElement.offsetWidth, }) } - }, [nowTag]) + }, [nowTag, locale]) useEffect(() => { const currentTagElement = tagRefs.current[allTag.indexOf(nowTag)]?.current @@ -75,7 +76,7 @@ export default function Switch({ behavior: "smooth", }) } - }, [nowTag]) + }, [nowTag, locale]) return (
([]) + const locale = useLocale() useEffect(() => { const currentTabElement = tabRefs.current[tabs.indexOf(currentTab)] @@ -32,7 +33,7 @@ export default function TabSwitch({ w: currentTabElement.offsetWidth, }) } - }, [currentTab, tabs]) + }, [currentTab, tabs, locale]) return (