MCPcopy Create free account
hub / github.com/block/buzz / useEscapeKey

Function useEscapeKey

desktop/src/shared/hooks/useEscapeKey.ts:9–21  ·  view source on GitHub ↗
(onEscape: () => void, enabled: boolean = true)

Source from the content-addressed store, hash-verified

7 * Pass `enabled: false` to skip registering the listener entirely.
8 */
9export function useEscapeKey(onEscape: () => void, enabled: boolean = true) {
10 React.useEffect(() => {
11 if (!enabled) return;
12 function handleKeyDown(event: KeyboardEvent) {
13 if (event.key === "Escape" && !event.defaultPrevented) {
14 event.preventDefault();
15 onEscape();
16 }
17 }
18 window.addEventListener("keydown", handleKeyDown);
19 return () => window.removeEventListener("keydown", handleKeyDown);
20 }, [enabled, onEscape]);
21}

Callers 4

UserProfilePanelFunction · 0.90
AgentSessionThreadPanelFunction · 0.90
MessageThreadPanelFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected