Modal API feels wired #2077
Answered
by
ljosberinn
ivanjeremic
asked this question in
General
-
We have How would I trigger a function when modal closes? |
Beta Was this translation helpful? Give feedback.
Answered by
ljosberinn
Sep 24, 2020
Replies: 1 comment 2 replies
-
You may wrap const { isOpen, onOpen, onClose } = useDisclosure();
function customOnClose() {
// do something here
onClose();
}
return <Modal onClose={customOnClose}>... FWIW, you don't need to use const [isOpen, setIsOpen] = useState(false);
function open() {
// custom logic here
setIsOpen(true);
}
function close() {
// custom logic here
setIsOpen(false);
}
return (
<>
<button type="button" onClick={open}>toggle</button>
<Modal isOpen={isOpen} onClose={close}>...</Modal>
</>
) |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
ljosberinn
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You may wrap
onClose
in your own function and forward that:FWIW, you don't need to use
useDisclosure
necessarily. You can reinvent the entire thing with your own states instead, but it usually leads to more code: