Skip to content

Commit

Permalink
fix: add locale dependency to component rendering effects
Browse files Browse the repository at this point in the history
  • Loading branch information
hamster1963 committed Feb 13, 2025
1 parent e55a60c commit a6aa91d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
7 changes: 4 additions & 3 deletions components/Switch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -19,6 +19,7 @@ export default function Switch({
const scrollRef = useRef<HTMLDivElement>(null)
const tagRefs = useRef(allTag.map(() => createRef<HTMLDivElement>()))
const t = useTranslations("ServerListClient")
const locale = useLocale()
const [indicator, setIndicator] = useState<{ x: number; w: number }>({
x: 0,
w: 0,
Expand Down Expand Up @@ -58,7 +59,7 @@ export default function Switch({
w: currentTagElement.offsetWidth,
})
}
}, [nowTag])
}, [nowTag, locale])

useEffect(() => {
const currentTagElement = tagRefs.current[allTag.indexOf(nowTag)]?.current
Expand All @@ -75,7 +76,7 @@ export default function Switch({
behavior: "smooth",
})
}
}, [nowTag])
}, [nowTag, locale])

return (
<div
Expand Down
5 changes: 3 additions & 2 deletions components/TabSwitch.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use client"

import { cn } from "@/lib/utils"
import { useTranslations } from "next-intl"
import { useLocale, useTranslations } from "next-intl"
import { useEffect, useRef, useState } from "react"

export default function TabSwitch({
Expand All @@ -19,6 +19,7 @@ export default function TabSwitch({
w: 0,
})
const tabRefs = useRef<(HTMLDivElement | null)[]>([])
const locale = useLocale()

useEffect(() => {
const currentTabElement = tabRefs.current[tabs.indexOf(currentTab)]
Expand All @@ -32,7 +33,7 @@ export default function TabSwitch({
w: currentTabElement.offsetWidth,
})
}
}, [currentTab, tabs])
}, [currentTab, tabs, locale])

return (
<div className="z-50 flex flex-col items-start rounded-[50px]">
Expand Down

0 comments on commit a6aa91d

Please sign in to comment.