Shadcn Modal Manager

Hooks

Hooks for interacting with the modal system

useModal()

The primary hook for controlling a modal instance. Can be used inside the modal component or with a reference to control a specific modal.

// Inside a modal
const modal = useModal();

// Outside (controlling specific modal)
const modal = useModal("modal-id");
const modal = useModal(ModalComponent);

Returns ModalHandler

PropertyTypeDescription
isOpenbooleanWhether the modal is open
open(data?) => PromiseFunction to open the modal
close(result?) => voidFunction to close the modal
dismiss() => voidFunction to dismiss without result
modalIdstringThe unique ID of this modal
dataTDataCurrent data passed to modal

useModalData()

Retrieves the typed data passed to the modal via open(). Must be used inside a modal component.

function useModalData<TData>(): TData | undefined

Example

const content = useModalData<{ message: string }>();
return <p>{content?.message}</p>;

useModalConfig()

Retrieves the configuration flags for the current modal.

function useModalConfig(): InternalModalConfig

Returns object containing disableClose, keepMounted etc.

On this page