react-clicks is a React.js hook enabling easy management of various click types(single, double & long click) .
Written in TypeScript. Optimised for both desktop & mobile.
Credits to Nitish for the pretty picture.
https://codesandbox.io/s/react-clicks-example-tt5pt5
npm install react-clicks
yarn add react-clicks
There's an example/
project showing the most basic usage.
import { useReactClicks } from 'react-clicks'
const App = () => {
const clickProps = useReactClicks({
singleClick: (e: ClickEventType) => {...},
doubleClick: (e: ClickEventType) => {...},
longClick: (e: ClickEventType) => {...}
})
return(
<>
<button {...clickProps}>I'm Hooked</button>
</>
)
}
The amount of milliseconds required between the first & the second click in order to treat it as a double click
If you don't disable the context menu, long clicks on mobile will open the mobile context menu.
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.