Skip to content

Instantly share code, notes, and snippets.

@brandonchadlange
Created September 26, 2022 19:41
Show Gist options
  • Save brandonchadlange/eeaf54aecb274dd9bc8af125739863b7 to your computer and use it in GitHub Desktop.
Save brandonchadlange/eeaf54aecb274dd9bc8af125739863b7 to your computer and use it in GitHub Desktop.
Modal with no dependancies
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