Created
September 26, 2022 19:41
-
-
Save brandonchadlange/eeaf54aecb274dd9bc8af125739863b7 to your computer and use it in GitHub Desktop.
Modal with no dependancies
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useState } from "react"; | |
export interface BodyProps { | |
close: () => void; | |
} | |
interface UseModalProps { | |
Body: (props: BodyProps) => JSX.Element; | |
} | |
const useModal = ({ Body }: UseModalProps) => { | |
const [opened, setOpened] = useState(false); | |
const open = () => { | |
setOpened(true); | |
}; | |
const close = () => { | |
setOpened(false); | |
}; | |
return { | |
Modal: () => ( | |
<Modal opened={opened} onClose={close}> | |
<Body close={close} /> | |
</Modal> | |
), | |
open, | |
close, | |
}; | |
}; | |
export default useModal; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment