How is the <AlertDialogAction /> meant to be used? I'm confused. #8873
Unanswered
florianmartens
asked this question in
Q&A
Replies: 1 comment
-
|
const [open, setOpen] = useState(false)
const handleAction = async () => {
await someAsyncOperation()
setOpen(false) // Close only after completion
}
<AlertDialog open={open} onOpenChange={setOpen}>
{/* ... */}
<AlertDialogAction onClick={handleAction}>Continue</AlertDialogAction>
</AlertDialog>The controlled |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
One of my favorite components in shadcn is the
<AlertDialog />. But to this day, I don't know how it is meant to be used.Obviously, it is meant to be paired with some form of action. Probably an async action. But the button just closes the dialog. It does not wait for any async action. Just closes the dialog without waiting for anything. So, attaching an
onClickhandler seems like a bad idea and instant memory leakWhen I first saw the
<AlertDialogAction />I thought it would be possible to register an action on the top-level dialog that returns a promise. When clicking the button, it would then wait for the promise to resolve and close. This would be great to allow the dialog to be uncontrolled too. But as of today:<AlertDialog />Can someone tell me how this component is meant to be used and why the
<AlertDialogAction />exists?Can't find anything in the radix or shad docs.
Beta Was this translation helpful? Give feedback.
All reactions