React - What's the difference between onKeyPress and onKeyDown?

0 points
Asked by:
Dirask Community

What is the difference between onKeyPress, onKeyDown and onKeyUp events in React?

1 answer
0 points
Answered by:
Dirask Community

I found out that:

  • onKeyDown┬áhappens first,
  • onKeyPress┬áhappens second (when text is entered),
  • onKeyUp┬áhappens last.

They are analogous to:

  • onMouseDown,
  • onClick,
  • onMouseUp.


The onKeyPress is deprecated, which means that this feature is no longer recommended.

Runnable example:

// ONLINE-RUNNER:browser;

window.addEventListener("keydown", log);
window.addEventListener("keypress", log);
window.addEventListener("keyup", log);

function log(event){
  console.log( event.type );
0 comments Add comment
Native Advertising
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

ÔŁĄ´ŞĆ­čĺ╗ ­čÖé