Skip to content

Commit d91d907

Browse files
committed
fix: fix activeKay props issue.
1 parent fa56479 commit d91d907

2 files changed

Lines changed: 8 additions & 8 deletions

File tree

core/src/Tabs.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { FC, isValidElement, PropsWithChildren, useEffect, useLayoutEffect, useMemo } from 'react';
1+
import React, { FC, isValidElement, PropsWithChildren, useLayoutEffect } from 'react';
22
import { useDrop } from 'react-dnd';
33
import { useDataContext, InitialState } from './store';
44
import { ItemTypes } from './Tab';
@@ -10,10 +10,6 @@ export const Tabs: FC<PropsWithChildren<TabsProps>> = ({ children, activeKey, ..
1010
accept: ItemTypes.Tab,
1111
}));
1212

13-
useMemo(() => {
14-
dispatch!({ activeKey });
15-
}, [activeKey]);
16-
1713
useLayoutEffect(() => {
1814
if (children) {
1915
const data: InitialState['data'] = [];

core/src/index.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { DndProvider } from 'react-dnd';
2-
import { FC, PropsWithChildren } from 'react';
2+
import { FC, PropsWithChildren, useEffect, useState } from 'react';
33
import { HTML5Backend } from 'react-dnd-html5-backend';
44
import { Tabs } from './Tabs';
55
import { Provider } from './store';
@@ -17,13 +17,17 @@ export interface TabsProps extends React.DetailedHTMLProps<React.HTMLAttributes<
1717
onTabDrop?: (id: string, index?: number) => void;
1818
}
1919

20-
const TabContainer: FC<PropsWithChildren<TabsProps>> = ({ activeKey, onTabClick, onTabDrop, ...props }) => {
20+
const TabContainer: FC<PropsWithChildren<TabsProps>> = ({ activeKey: keyId, onTabClick, onTabDrop, ...props }) => {
2121
const tabClick = useEventCallback(onTabClick!);
2222
const tabDrop = useEventCallback(onTabDrop!);
23+
const [activeKey, setActiveKey] = useState(keyId);
24+
25+
useEffect(() => setActiveKey(keyId), [keyId]);
26+
2327
return (
2428
<DndProvider backend={HTML5Backend}>
2529
<Provider init={{ data: [], activeKey, onTabClick: tabClick, onTabDrop: tabDrop }}>
26-
<Tabs {...props} activeKey={activeKey} />
30+
<Tabs {...props} />
2731
</Provider>
2832
</DndProvider>
2933
);

0 commit comments

Comments
 (0)