import type React from '../lib/teact/teact'; import { IS_TOUCH_ENV, MouseButton } from '../util/windowEnvironment'; import useLastCallback from './useLastCallback'; type EventArg = React.MouseEvent; type EventHandler = (e: EventArg) => void; export function useFastClick(callback?: EventHandler) { const handler = useLastCallback((e: EventArg) => { if (e.type === 'mousedown' && e.button !== MouseButton.Main) { return; } callback!(e); }); return IS_TOUCH_ENV ? { handleClick: callback ? handler : undefined } : { handleMouseDown: callback ? handler : undefined }; }