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
参数名 | 描述 | 类型 | 默认值 |
---|---|---|---|
target | dom对象 | 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;