use-double-click
is a simple React hook for differentiating single and double clicks on the same component.
Demo
Native onClick() + onDoubleClick()
[native] onClick: 0[native] onDoubleClick: 0useDoubleClick() Hook
[hook] onSingleClick: 0[hook] onDoubleClick: 0What's wrong with native onDoubleClick()
?
When you double click on a React component, it's onClick()
callback fires twice alongside your single onDoubleClick()
callback. This effect isn't desirable when a single click and a double click have different functions!
useDoubleClick()
waits within a latency window after a click for a secondary click, and only after this period either the onSingleClick()
or onDoubleClick()
callback will fire a single time.
Installation
This library is built with hooks and requires React >= 16.8.0
Terminal
Basic Usage
componentsClicker.js