MCPcopy
hub / github.com/graphql/graphiql / useKeyMap

Function useKeyMap

packages/graphiql-react/src/editor/hooks.ts:135–156  ·  view source on GitHub ↗
(
  editor: CodeMirrorEditor | null,
  keys: string[],
  callback?: EmptyCallback,
)

Source from the content-addressed store, hash-verified

133type EmptyCallback = () => void;
134
135export function useKeyMap(
136 editor: CodeMirrorEditor | null,
137 keys: string[],
138 callback?: EmptyCallback,
139) {
140 useEffect(() => {
141 if (!editor) {
142 return;
143 }
144 for (const key of keys) {
145 editor.removeKeyMap(key);
146 }
147
148 if (callback) {
149 const keyMap: Record<string, EmptyCallback> = {};
150 for (const key of keys) {
151 keyMap[key] = () => callback();
152 }
153 editor.addKeyMap(keyMap);
154 }
155 }, [editor, keys, callback]);
156}
157
158export type UseCopyQueryArgs = {
159 /**

Callers 3

useHeaderEditorFunction · 0.90
useVariableEditorFunction · 0.90
useQueryEditorFunction · 0.90

Calls 1

callbackFunction · 0.85

Tested by

no test coverage detected