Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

469 B
Raw Blame
import { useEffect } from "react";

/**
 * Calls `onClose` when the Escape key is pressed while `active` is true.
 */
export function useEscapeKey(active: boolean, onClose: () => void) {
  useEffect(() => {
    if (!active) return;
    const handler = (e: KeyboardEvent) => {
      if (e.key === "Escape") onClose();
    };
    document.addEventListener("keydown", handler);
    return () => document.removeEventListener("keydown", handler);
  }, [active, onClose]);
}