mirror of
https://github.com/zhigang1992/react.git
synced 2026-03-28 22:46:38 +08:00
27 lines
620 B
TypeScript
27 lines
620 B
TypeScript
import { Dispatch, MutableRefObject, SetStateAction } from 'react'
|
|
import useCurrentState from 'components/utils/use-current-state'
|
|
|
|
const useModal = (initialVisible: boolean = false): {
|
|
visible: boolean
|
|
setVisible: Dispatch<SetStateAction<boolean>>
|
|
currentRef: MutableRefObject<boolean>
|
|
bindings: {
|
|
open: boolean
|
|
onClose: () => void
|
|
}
|
|
} => {
|
|
const [visible, setVisible, currentRef] = useCurrentState<boolean>(initialVisible)
|
|
|
|
return {
|
|
visible,
|
|
setVisible,
|
|
currentRef,
|
|
bindings: {
|
|
open: visible,
|
|
onClose: () => setVisible(false),
|
|
},
|
|
}
|
|
}
|
|
|
|
export default useModal
|