EN
React - What's the difference between onKeyPress and onKeyDown?
1
answers
0
points
What is the difference between onKeyPress, onKeyDown and onKeyUp events in React?
1 answer
0
points
I found out that:
onKeyDownhappens first,onKeyPresshappens second (when text is entered),onKeyUphappens last.
They are analogous to:
onMouseDown,onClick,onMouseUp.
Note:
The
onKeyPressis 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