Skip to main content

useDoubleClick

React sensor hook that controls double click and single click

Usage

Live Editor

function Demo() {
  const element = useRef<HTMLButtonElement>(null);
  const [text, setText] = useState("no click");

  useDoubleClick({
    target: element,
    onSingleClick: () => {
      setText("single click");
    },
    onDoubleClick: () => {
      setText("double click");
    },
  });
  return (
    <div>
      <button ref={element}>Click Me</button>
      <p>{text}</p>
    </div>
  );
};

Result
Loading...

API

useDoubleClick

Returns

void

Arguments

ArgumentDescriptionTypeDefaultValue
props-UseDoubleClickProps (Required)-

UseDoubleClickProps

PropertyDescriptionTypeDefaultValue
targetdom elementBasicTarget<Element> (Required)-
latencylatency time (milliseconds)number | undefined-
onSingleClicksingle click event handler((e?: MouseEvent | TouchEvent) => void) | undefined-
onDoubleClickdouble click event handler((e?: MouseEvent | TouchEvent) => void) | undefined-

BasicTarget

export type BasicTarget<T extends TargetType = Element> = (() => TargetValue<T>) | TargetValue<T> | MutableRefObject<TargetValue<T>>;

TargetValue

type TargetValue<T> = T | undefined | null;

TargetType

type TargetType = HTMLElement | Element | Window | Document | EventTarget;