import { useCallback } from 'react'; import { Event } from '../events'; import { normalizeNonFinite } from '../utils/normalizeNonFinite'; /** * A function that takes a generic event as argument. */ type Callback = (event: E) => void; /** * A function that takes the synthetic version of a generic event as argument. */ type NativeCallback = (event: { nativeEvent: E }) => void; /** * Create a proxy function that unwraps native events. */ export function useProxy(): ( callback?: Callback ) => NativeCallback { return useCallback( (callback?: Callback) => (event: { nativeEvent: E }) => { // Remove the target field from the event as it's React Native internal metadata const { target: _target, ...eventWithoutTarget } = event.nativeEvent as any; const sanitized = normalizeNonFinite(eventWithoutTarget); callback?.(sanitized as E); }, [] ); }