Skip to content

Commit e46628d

Browse files
committed
fix: handlersMapRef contains old references to state handlers after first Tabs rerender
1 parent ee84f65 commit e46628d

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/lib/tabs/useTabs.tsx

+8-9
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,6 @@ const useTabsState = (apiRef: MutableRefObject<TabsApi>, props: TabsProps) => {
128128
initialStartPinnedTabs = [],
129129
initialEndPinnedTabs = [],
130130
} = props;
131-
const handlersMapRef = useRef<ControlledStateCallbacks>({
132-
tabs: onTabsChange,
133-
activeTabId: onActiveTabIdChange,
134-
startPinnedTabs: onStartPinnedTabsChange,
135-
endPinnedTabs: onEndPinnedTabsChange,
136-
childTabsApi: () => {},
137-
parentTabsApi: () => {},
138-
});
139131

140132
const stateRef = useRef<State>({
141133
tabs: initialTabs,
@@ -164,7 +156,14 @@ const useTabsState = (apiRef: MutableRefObject<TabsApi>, props: TabsProps) => {
164156
if (runHandlers) {
165157
subStateKeys.forEach((subStateKey) => {
166158
const subState = newState[subStateKey];
167-
const subStateHandler = handlersMapRef.current[subStateKey];
159+
const subStateHandler = {
160+
tabs: onTabsChange,
161+
activeTabId: onActiveTabIdChange,
162+
startPinnedTabs: onStartPinnedTabsChange,
163+
endPinnedTabs: onEndPinnedTabsChange,
164+
childTabsApi: () => {},
165+
parentTabsApi: () => {},
166+
}[subStateKey];
168167
// @ts-ignore
169168
subStateHandler?.(subState);
170169
});

0 commit comments

Comments
 (0)