• Custom React hook that detects when the Esc key is pressed.

    This hook listens for the keydown event on the specified element or the window if no element is specified. When the Esc key (key code 27) is pressed, the provided callback function is executed.

    Example

    const MyComponent = () => {
    const handleEscape = () => {
    console.log('Escape key pressed!');
    };

    useOnEscape(handleEscape);

    return <div>Press the `Esc` key!</div>;
    };

    Parameters

    • callback: (() => void)

      The callback function to execute when the Esc key is pressed.

        • (): void
        • Returns void

    • Optional options: IUseOnEscapeProps

      Optional settings for managing the event listener behavior.

    Returns void