Other Keyboard Events

Other keyboard events in React are:

EventOccurs WhenDescription
onkeydownThe user presses a keyUsed to detect initial keypress
onkeypressThe user presses a keyIt is now deprecated and it represented only character input.
onkeyupthe user releases a keyUsed to detect when a key is released


React onKeyDown Event

React onKeyDown event occurs on a key press event in a browser. onKeyDown is an updated event in place of onKeyPress.

onKeyPress is now deprecated because it does not work for all keys (like CTRL, SHIFT, and ALT) in all browsers, so onKeyDown is a new event listener that is used to detect the key press event.

It is similar to the HTML DOM onkeydown event but uses the camelCase convention in React.

Syntax:

onKeyDown={keyDownFunction}

Parameter:

  • KeyDownFunction: It is a function that will call once any key is pressed from the Keyboard.

Return type:

  • KeyboardEvent object that provides information about the keyboard key that was pressed.

Similar Reads

Examples of onKeyDown Event in React

Below are some of the examples of the onKeyDown event in React. These example demonstrates the working of the onKeyDown event and provides a better learning experience....

Other Keyboard Events

Other keyboard events in React are:...

Contact Us