Skip to content

Commit 7ba6ad7

Browse files
refactor: delete useEffectOnce hook (#18886)
Co-authored-by: Heloise Lui <71858203+heloiselui@users.noreply.github.com>
1 parent f574ad0 commit 7ba6ad7

File tree

2 files changed

+8
-39
lines changed

2 files changed

+8
-39
lines changed

packages/react/src/components/Tabs/Tabs.tsx

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import { Grid } from '../Grid';
3131
import { isElement } from 'react-is';
3232
import { Tooltip } from '../Tooltip';
3333
import { useControllableState } from '../../internal/useControllableState';
34-
import { useEffectOnce } from '../../internal/useEffectOnce';
3534
import { useId } from '../../internal/useId';
3635
import useIsomorphicEffect from '../../internal/useIsomorphicEffect';
3736
import { useMergedRefs } from '../../internal/useMergedRefs';
@@ -601,15 +600,15 @@ function TabList({
601600
}
602601
}
603602

604-
useEffectOnce(() => {
603+
useEffect(() => {
605604
const tab = tabs.current[selectedIndex];
606605
if (scrollIntoView && tab) {
607606
tab.scrollIntoView({
608607
block: 'nearest',
609608
inline: 'nearest',
610609
});
611610
}
612-
});
611+
}, []);
613612

614613
useEffect(() => {
615614
//adding 1 in calculation for firefox support
@@ -627,7 +626,7 @@ function TabList({
627626
}
628627
}, [scrollLeft, children, dismissable, isScrollable]);
629628

630-
useEffectOnce(() => {
629+
useEffect(() => {
631630
if (tabs.current[selectedIndex]?.disabled) {
632631
const activeTabs = tabs.current.filter((tab) => {
633632
return !tab.disabled;
@@ -638,7 +637,7 @@ function TabList({
638637
setSelectedIndex(tabs.current.indexOf(tab));
639638
}
640639
}
641-
});
640+
}, []);
642641

643642
useIsomorphicEffect(() => {
644643
if (ref.current) {
@@ -941,7 +940,7 @@ function TabListVertical({
941940
}
942941
}
943942

944-
useEffectOnce(() => {
943+
useEffect(() => {
945944
if (tabs.current[selectedIndex]?.disabled) {
946945
const activeTabs = tabs.current.filter((tab) => {
947946
return !tab.disabled;
@@ -952,7 +951,7 @@ function TabListVertical({
952951
setSelectedIndex(tabs.current.indexOf(tab));
953952
}
954953
}
955-
});
954+
}, []);
956955

957956
useEffect(() => {
958957
function handler() {
@@ -1666,7 +1665,7 @@ const TabPanel = React.forwardRef<HTMLDivElement, TabPanelProps>(
16661665
[`${prefix}--tab-content--interactive`]: interactiveContent,
16671666
});
16681667

1669-
useEffectOnce(() => {
1668+
useEffect(() => {
16701669
if (!panel.current) {
16711670
return;
16721671
}
@@ -1676,7 +1675,7 @@ const TabPanel = React.forwardRef<HTMLDivElement, TabPanelProps>(
16761675
setInteractiveContent(true);
16771676
setTabIndex(-1);
16781677
}
1679-
});
1678+
}, []);
16801679

16811680
// tabindex should only be 0 if no interactive content in children
16821681
useEffect(() => {

packages/react/src/internal/useEffectOnce.js

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)