Skip to content

hideModal() from within Dialog component #48

@barrettg

Description

@barrettg

I'm wanting to create a self contained Dialog that has some logic in it as well. When the OK button is pressed, the business logic executes and the modal is closed. Is it possible to call hideModal from within the dialog itself?

const ConfirmationDialog: React.FC<Props> = ({ title, description, ...props }) => {
    const { hideModal } = useModal();
    const handleClose = () => {
        // Do stuff here
        ...
        hideModal(); // What is the modal id?
    };
    return (
        <Dialog {...props}>
            <DialogTitle>{title}</DialogTitle>
            <DialogContent>
                <DialogContentText>{description}</DialogContentText>
            </DialogContent>
            <DialogActions>
                <Button onClick={handleClose} color="primary">
                    Ok
                </Button>
            </DialogActions>
        </Dialog>
    );
};

Meanwhile somewhere else in my app:

showModal(ConfirmationDialog, {
  title: 'Hello World',
  description: 'description text',
});

Thanks for a great library!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions