跳到主要内容

useDoubleClick

双击跟踪

Usage

实时编辑器

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>
  );
};

结果
Loading...

API

useDoubleClick

Returns

void

Arguments

参数名描述类型默认值
props-UseDoubleClickProps (必填)-

UseDoubleClickProps

参数名描述类型默认值
targetdom对象BasicTarget<Element> (必填)-
latency延迟时间(毫秒)number | undefined-
onSingleClick单击事件处理函数((e?: MouseEvent | TouchEvent) => void) | undefined-
onDoubleClick双击事件处理函数((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;