Closed fivethreeo closed 3 years ago
Hey,
because useLongPress
hook returns object with listeners you can manually attach them to proper elements for example:
const callback = useCallback(() => { console.log('long press'); }, []);
const {
onMouseDown,
onMouseUp,
onMouseLeave,
onTouchStart,
onTouchEnd
} = useLongPress(callback);
<body onTouchEnd={onTouchEnd}>
<div onMouseUp={onMouseUp}>...</div>
</body>
@fivethreeo Does this solution address your case?
I think so, but a example with binding handlers using js dom binding and useEffect/useLayoutEffect, refs and to go crazy touch events ;)
Then you could do dragging outside the element while holding. Also mouseleave should be optional for the same reason. Was thinking of using this for a interactive clock component. Then I could drag around the clock without callbacks being called if I veer out of the clock.