mirror of
https://github.com/zhigang1992/react.git
synced 2026-04-23 20:00:56 +08:00
29 lines
615 B
TypeScript
29 lines
615 B
TypeScript
import { Dispatch, MutableRefObject, SetStateAction } from 'react'
|
|
import useCurrentState from '../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
|