MCPcopy Create free account
hub / github.com/adobe/react-spectrum / useEvent

Function useEvent

packages/react-aria/src/utils/useEvent.ts:18–34  ·  view source on GitHub ↗
(
  ref: RefObject<T | null>,
  event: Extract<K, string> | (string & {}),
  listener?: (this: T, ev: EventMapType<Exclude<T, null>>[K]) => any,
  options?: boolean | AddEventListenerOptions
)

Source from the content-addressed store, hash-verified

16import {useEffectEvent} from './useEffectEvent';
17
18export function useEvent<T extends EventTarget, K extends keyof EventMapType<T>>(
19 ref: RefObject<T | null>,
20 event: Extract<K, string> | (string & {}),
21 listener?: (this: T, ev: EventMapType<Exclude<T, null>>[K]) => any,
22 options?: boolean | AddEventListenerOptions
23): void {
24 let handleEvent = useEffectEvent(listener);
25 let isDisabled = listener == null;
26
27 useEffect(() => {
28 if (isDisabled || ref.current == null) {
29 return;
30 }
31
32 return addEvent(ref.current, event, handleEvent, options);
33 }, [ref, event, options, isDisabled]);
34}

Callers 15

ExampleFunction · 0.90
FocusScope.test.jsFile · 0.90
useScrollWheelFunction · 0.90
usePreviewTriggerFunction · 0.90
useLoadMoreFunction · 0.90
useTokenFieldFunction · 0.90
useSelectionChangeFunction · 0.90
useTokenFunction · 0.90
useComboBoxFunction · 0.90
useRangeCalendarFunction · 0.90
useSelectableCollectionFunction · 0.90
useSubmenuTriggerFunction · 0.90

Calls 2

useEffectEventFunction · 0.90
addEventFunction · 0.90

Tested by 1

ExampleFunction · 0.72