Programmatically Close Dialog #1504
-
I have a dialog that will save changes - but I want it to close if the submit method is called successfully and unsure on how to accomplish this? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
To control the Dialog you can do this const [open, setOpen] = React.useState(false)
<Dialog open={open} onOpenChange={setOpen}>
...
</Dialog> |
Beta Was this translation helpful? Give feedback.
-
you can use react useRef hook.
|
Beta Was this translation helpful? Give feedback.
-
This is the code I use to dismiss my dialog. I put it into a hook to makes things easier. It only works on client import React from 'react'
const useDismissModal = () => {
const dismiss = () => (document.querySelector('[data-state="open"]') as HTMLDivElement).click()
return {
dismiss
}
}
export default useDismissModal |
Beta Was this translation helpful? Give feedback.
To control the Dialog you can do this