diff --git a/src/components/Tabs/index.tsx b/src/components/Tabs/index.tsx index 821139c..ba2a0f7 100644 --- a/src/components/Tabs/index.tsx +++ b/src/components/Tabs/index.tsx @@ -1,6 +1,6 @@ import { cn } from '@/lib/utils' import { useDeepBrowsing } from '@/providers/DeepBrowsingProvider' -import { useEffect, useRef, useState } from 'react' +import { useMemo } from 'react' import { useTranslation } from 'react-i18next' type TabDefinition = { @@ -21,62 +21,38 @@ export default function Tabs({ }) { const { t } = useTranslation() const { deepBrowsing, lastScrollTop } = useDeepBrowsing() - const tabRefs = useRef<(HTMLDivElement | null)[]>([]) - const [indicatorStyle, setIndicatorStyle] = useState({ width: 0, left: 0 }) - - useEffect(() => { - const handleResize = () => { - const activeIndex = tabs.findIndex((tab) => tab.value === value) - if (tabs.length === 4) { - console.log('notification tabs', activeIndex, value) - } - if (activeIndex >= 0 && tabRefs.current[activeIndex]) { - const activeTab = tabRefs.current[activeIndex] - const { offsetWidth, offsetLeft } = activeTab - const padding = 24 // 12px padding on each side - if (tabs.length === 4) { - console.log('notification tabs', offsetWidth, offsetLeft, padding) - } - setIndicatorStyle({ - width: offsetWidth - padding, - left: offsetLeft + padding / 2 - }) - } - } - window.addEventListener('resize', handleResize) - setTimeout(() => handleResize(), 20) // ensure tabs are rendered before calculating - return () => { - window.removeEventListener('resize', handleResize) - } - }, [value]) + const activeIndex = useMemo(() => tabs.findIndex((tab) => tab.value === value), [value, tabs]) return (