EXEPERTAI LAB

Research alpha

Time Machine
EXEPERTAI LAB
GALLERY / COLLECTION
← Browse Astryx gallery
AlertDialog·hook·@astryxdesign/core

useImperativeAlertDialog

Hook for showing an alert dialog without managing open state. Call alert.show(options) to open and alert.hide() to close. Render alert.element in your JSX tree.

Open in Playground @astryxdesign/core/AlertDialog

Signature

Call shape
useImperativeAlertDialog(): ImperativeAlertDialogReturn

Showcases and examples

1 documented example

AlertDialog — Delete

A delete button that asks the user to confirm before deleting.

Preview loads on approachPreview loads on approach
Exact source · alert-dialog-delete-confirmation
// Copyright (c) Meta Platforms, Inc. and affiliates.

'use client';

import {
  AlertDialog,
  useImperativeAlertDialog,
} from '@astryxdesign/core/AlertDialog';

// Remove isInline for production — alert dialogs should be modal.
export default function AlertDialogDeleteConfirmation() {
  const alert = useImperativeAlertDialog();

  const alertProps = {
    title: 'Delete item?',
    description:
      'This action cannot be undone. The item and all its data will be permanently removed.',
    actionLabel: 'Delete',
  } as const;

  return (
    <>
      <AlertDialog
        isOpen
        isInline
        onOpenChange={() => {}}
        {...alertProps}
        onAction={() =>
          alert.show({...alertProps, onAction: () => alert.hide()})
        }
      />
      {alert.element}
    </>
  );
}

Usage

Hook for showing an alert dialog without managing open state. Call alert.show(options) to open and alert.hide() to close. Render alert.element in your JSX tree.

Typed props

PropType and behavior
show(options: AlertDialogOptions) => void
Show the alert dialog with the given options. Options are the same as AlertDialog props minus isOpen/onOpenChange.
hide() => void
Hide the alert dialog.
isOpenboolean
Whether the dialog is currently open.
elementReactNode
The dialog element: render this in your JSX tree.