import { useEffect } from "react"; /** Dismiss a dialog with the Escape key while `active` is true. */ export function useEscapeKey(active: boolean, onEscape: () => void) { useEffect(() => { if (!active) return; const handler = (e: KeyboardEvent) => { if (e.key === "Escape") onEscape(); }; document.addEventListener("keydown", handler); return () => document.removeEventListener("keydown", handler); }, [active, onEscape]); }