useTap

Recognises a still tap and a double tap on an element.

@internote/canvas-sdk/reactHook
On this page
import { useTap } from '@internote/canvas-sdk/react';

moved() answers whether the last press travelled past the slop, for an element whose onClick must ignore a press that panned the canvas under it — a click still fires at the end of a drag that started and ended on the same element.

#Signature

(options: TapOptions<React.PointerEvent<Element>>): {
    bind: TapProps;
    moved: () => boolean;
}

#Parameters

options
What to call, and which pointers count. Read at event time, so it may be rebuilt every render.

#Returns

bind, the props to spread, and moved.

#Example

const { bind, moved } = useTap({ onDoubleTap: reset, pointerTypes: ['touch', 'pen'] });
<button {...bind} onClick={() => { if (!moved()) flip(); }} onDoubleClick={reset} />

Declared in packages/canvas-sdk/src/react/gestures/use-tap.ts:147.

Last updated