beautiful-react-hooks
Version:
A collection of beautiful (and hopefully useful) React hooks to speed-up your components and hooks development
24 lines (23 loc) • 1.2 kB
TypeScript
import { RefObject } from 'react';
/**
* Returns a frozen object of callback setters to handle the touch events.<br/>
* It accepts a DOM ref representing the events target. <br/>
* If a target is not provided the events will be globally attached to the document object.
* <br/>
* ### Shall the `useTouchEvents` callbacks replace the standard mouse handler props?
*
* **They shall not!**<br />
* **useTouchEvents is meant to be used to abstract more complex hooks that need to control mouse**, for instance:
* a drag n drop hook.<br />
* Using useTouchEvents handlers instead of the classic props approach it's just as bad as it sounds since you'll
* lose the React SyntheticEvent performance boost.<br />
* If you were doing something like the following:
*
*/
declare const useTouchEvents: <TElement extends HTMLElement>(targetRef?: RefObject<TElement>) => Readonly<{
onTouchStart: import("./shared/types").CallbackSetter<TouchEvent>;
onTouchEnd: import("./shared/types").CallbackSetter<TouchEvent>;
onTouchCancel: import("./shared/types").CallbackSetter<TouchEvent>;
onTouchMove: import("./shared/types").CallbackSetter<TouchEvent>;
}>;
export default useTouchEvents;