1
- import { Children , isValidElement , useContext , useRef , useState , useTransition } from 'react' ;
1
+ import { Children , isValidElement , useRef , useState , useTransition } from 'react' ;
2
2
3
- import { TabContext } from '../Tab.context' ;
4
3
import { StyledFixedTab , StyledList , StyledScrollableTab } from '../Tabs.style' ;
5
4
import { TabListProps , TabPanelProps , TabProps } from '../Tabs.type' ;
6
5
@@ -12,15 +11,10 @@ export const useTabs = <TabType extends string>({
12
11
scrollable ?:boolean ;
13
12
} ) => {
14
13
const [ isPending , startTransition ] = useTransition ( ) ;
14
+ const [ currentTab , setCurrentTab ] = useState < TabType > ( defaultTab ) ;
15
15
16
16
const Tabs = ( { children} :{ children :React . ReactNode } ) => {
17
- const [ currentTab , setCurrentTab ] = useState < string > ( defaultTab ) ;
18
-
19
- return (
20
- < TabContext . Provider value = { { currentTab, setCurrentTab} } >
21
- < div > { children } </ div >
22
- </ TabContext . Provider >
23
- ) ;
17
+ return < div > { children } </ div > ;
24
18
} ;
25
19
26
20
const List = ( { children, size= 'large' , ...props } :TabListProps ) => {
@@ -44,16 +38,11 @@ export const useTabs = <TabType extends string>({
44
38
} ;
45
39
46
40
const Tab = ( { children, id, onClick, ...props } :TabProps < TabType > ) => {
47
- const { currentTab, setCurrentTab} = useContext ( TabContext ) ?? {
48
- currentTab :undefined ,
49
- setCurrentTab :undefined ,
50
- startTransition :undefined ,
51
- } ;
52
41
const isSelected = currentTab === id ;
53
42
const tabRef = useRef < HTMLButtonElement > ( null ) ;
54
43
55
44
const onClickWrapper = ( event :React . MouseEvent < HTMLButtonElement , MouseEvent > ) => {
56
- startTransition ( ( ) => setCurrentTab ?.( id ) ) ;
45
+ startTransition ?. ( ( ) => setCurrentTab ?.( id ) ) ;
57
46
onClick ?.( event ) ;
58
47
} ;
59
48
@@ -113,8 +102,6 @@ export const useTabs = <TabType extends string>({
113
102
} ;
114
103
115
104
const Panel = ( { children, value, ...props } :TabPanelProps < TabType > ) => {
116
- const { currentTab} = useContext ( TabContext ) ?? { currentTab :undefined } ;
117
-
118
105
if ( currentTab !== value ) return ;
119
106
return (
120
107
< div role = "tabpanel" aria-labelledby = { value } tabIndex = { 0 } { ...props } >