UNPKG

preact-missing-hooks

Version:

A lightweight, extendable collection of missing React-like hooks for Preact — plus fresh, powerful new ones designed specifically for modern Preact apps.

38 lines (37 loc) 1.6 kB
import type { RefObject } from "preact"; export interface RageClickPayload { /** Number of clicks that triggered the rage click */ count: number; /** Last click event (e.g. for Sentry context) */ event: MouseEvent; } export interface UseRageClickOptions { /** Called when a rage click is detected. Use this to report to Sentry or your error tracker. */ onRageClick: (payload: RageClickPayload) => void; /** Minimum number of clicks in the time window to count as rage click. Default: 5 (Sentry-style). */ threshold?: number; /** Time window in ms. Default: 1000. */ timeWindow?: number; /** Max distance in px between clicks to count as same spot. Default: 30. Set to Infinity to ignore distance. */ distanceThreshold?: number; } /** * Detects "rage clicks" (repeated rapid clicks in the same area), e.g. when the UI * is unresponsive. Use the callback to report to Sentry or similar tools to surface * rage click issues and lower rage-click-related support. * * @param targetRef - Ref of the element to monitor (e.g. a button or card). * @param options - onRageClick callback and optional threshold, timeWindow, distanceThreshold. * * @example * ```tsx * const ref = useRef<HTMLButtonElement>(null) * useRageClick(ref, { * onRageClick: ({ count, event }) => { * Sentry.captureMessage('Rage click detected', { extra: { count, target: event.target } }) * }, * }) * return <button ref={ref}>Submit</button> * ``` */ export declare function useRageClick(targetRef: RefObject<HTMLElement | null>, options: UseRageClickOptions): void;