EN
React - onDoubleClick example
3 points
In this article, we would like to show you how to use onDoubleClick
event in React.
Quick solution:
xxxxxxxxxx
1
<button onDoubleClick={myFunction}>Click me</button>
In below example, we use handleDoubleClick
arrow function with button's onDoubleClick
property that handles double click event.
Runnable example:
xxxxxxxxxx
1
// Note: uncomment import lines in your React project.
2
// import React from react';
3
4
const handleDoubleClick = () => {
5
console.log('onDoubleClick event handled!');
6
};
7
8
const App = () => {
9
return (
10
<div className="App">
11
<button onDoubleClick={handleDoubleClick}>Click me</button>
12
</div>
13
);
14
};
15
16
const root = document.querySelector('#root');
17
ReactDOM.render(<App />, root );
Hint: React has it's own
onDoubleClick
property to handle double click event that is equivalent ofdblclick
event that is used by pure JavaScript.