Languages

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

0 points
Asked by:
Dirask Community
5460

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

1 answer
0 points
Answered by:
Dirask Community
5460

I found out that:

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

They are analogous to:

  • onMouseDown,
  • onClick,
  • onMouseUp.

Note:

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.

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

Join