Files
react/components/tabs/use-tabs.ts
2020-05-06 14:25:10 +08:00

31 lines
621 B
TypeScript

import { Dispatch, MutableRefObject, SetStateAction } from 'react'
import useCurrentState from '../utils/use-current-state'
const useTabs = (
initialValue: string,
): {
state: string
setState: Dispatch<SetStateAction<string>>
currentRef: MutableRefObject<string>
bindings: {
value: string
onChange: (val: string) => void
}
} => {
const [state, setState, currentRef] = useCurrentState<string>(initialValue)
return {
state,
setState,
currentRef,
bindings: {
value: state,
onChange: (val: string) => {
setState(val)
},
},
}
}
export default useTabs