Function useKeyCallback

  • Add a listener for a keydown event on a specific key.

    Example

    const MyComponent = () => {
    useKeyCallback("Escape", () => window.close());
    return <div>Press escape to close window</div>
    }

    Parameters

    • keyCode: string

      the specific key you want to listen to

    • callback: ((event) => void)

      the function that will be called when the key has been pressed. Receives the keydown event

        • (event): void
        • Parameters

          • event: KeyboardEvent

          Returns void

    • Optional active: boolean

      flag to indicate if the listener should be active right now

    Returns void

Generated using TypeDoc