When someone confirms a dialog, the calling code already has its answer, even though the dialog itself may need another fraction of a second to animate out. Removing it immediately cuts the transition short, while waiting for the final frame before returning the answer ties application behavior to presentation timing.
I built a headless React library to give those two concerns separate ownership. The library manages the registry, stack, and lifecycle, while the application supplies the dialog components and handles their appearance.
Answered does not mean removed
In this model, closing a dialog resolves its result right away and starts the exit. Removal waits until the exit finishes, backed by a duration fallback. Hiding is a separate operation that keeps the instance available.
Those distinctions start to matter once you have stacked dialogs and repeated close calls. An instance can still be visible after its caller already has an answer, or it can remain available while hidden. Flattening all of that into open or closed forces callers to rebuild the missing states on their own.
Putting that lifecycle inside the library means each application does not have to recreate it around its animations. The caller awaits an answer without having to manage the disappearing component.
The API must preserve the answer's type
Every registered overlay connects its name, input props, and result type together, so a confirmation dialog and a selection dialog can return different answers without forcing the caller to recover their types by hand.
Because those guarantees fail in different ways, I test public types separately from runtime behavior. A dialog whose exit lifecycle works cleanly can still expose an API that silently accepts missing props; just as easily, accurate type inference says nothing about what happens when a second close call hits an instance that is already leaving.
What remains with the component
Because a headless lifecycle manager does not render the dialog itself, it cannot supply the interaction details inside it. Accessible naming, keyboard behavior, and focus restoration remain responsibilities of the interface the application supplies.
Keeping that boundary explicit keeps the library small and makes its guarantees easy to inspect. The implementation and lifecycle tests are linked below.
Working through a reusable component contract?
Discuss a project ↗