werkbank
    Preparing search index...

    Function useKeyCallback

    • Returns a callback that triggers only when specific keys are pressed.

      Type Parameters

      • E extends HTMLElement

        The HTML element type.

      Parameters

      • keys: [KeyValues, ...KeyValues[]]

        An array of key values to listen for.

      • callback: UseKeyCallbackFn<E>

        The function to call when a matching key is pressed.

      Returns (e: KeyboardEvent<E>) => void

      A KeyboardEvent handler.

      This hook is useful for handling keyboard shortcuts or specific key interactions. It checks event.key against the provided list of keys.

      const onKeyDown = useKeyCallback(["Enter", " "], (e) => {
      submit();
      });
      return <div onKeyDown={onKeyDown} />;