@app-elements/use-successive-taps
v1.0.0
Published
A (P)React hook that fires a callback only after `n` taps or clicks.
Downloads
3
Readme
useSuccessiveTaps
useSuccessiveTaps takes a number of taps, a delay, and a callback, then returns a function that will only invoke the callback when it itself is invoked the specified number of times (with a pause no greater than the specified delay).
Installation
npm install --save @app-elements/use-successive-taps
Usage
import { useSuccessiveTaps } from '@app-elements/use-successive-taps'
const Stateful = (props) => {
// Create a handler to invoke "Test" mode only after our logo is tapped 10
times.
const handler = useSuccessiveTaps(10, 750, () => {
dispatch(toggleTestMode())
})
return (
<h1 onClick={handler}>Logo</h1>
)
}
Props
| Prop | Type | Default | Description |
|------------------------|------------|---------------|---------------------|
| numTaps
| Number | None | Number of successive taps
| delay
| Number | None | ms pause allowed between taps
| callback
| Function | None | function to invoke after successive taps