Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

useThrottledEventHandler.d.ts 1.1 KiB

3 лет назад
12345678910111213141516171819202122232425262728293031323334
  1. import { SyntheticEvent } from 'react';
  2. export declare type ThrottledHandler<TEvent> = ((event: TEvent) => void) & {
  3. clear(): void;
  4. };
  5. /**
  6. * Creates a event handler function throttled by `requestAnimationFrame` that
  7. * returns the **most recent** event. Useful for noisy events that update react state.
  8. *
  9. * ```tsx
  10. * function Component() {
  11. * const [position, setPosition] = useState();
  12. * const handleMove = useThrottledEventHandler<React.PointerEvent>(
  13. * (event) => {
  14. * setPosition({
  15. * top: event.clientX,
  16. * left: event.clientY,
  17. * })
  18. * }
  19. * )
  20. *
  21. * return (
  22. * <div onPointerMove={handleMove}>
  23. * <div style={position} />
  24. * </div>
  25. * );
  26. * }
  27. * ```
  28. *
  29. * @param handler An event handler function
  30. * @typeParam TEvent The event object passed to the handler function
  31. * @returns The event handler with a `clear` method attached for clearing any in-flight handler calls
  32. *
  33. */
  34. export default function useThrottledEventHandler<TEvent = SyntheticEvent>(handler: (event: TEvent) => void): ThrottledHandler<TEvent>;