import React, { useRef, PropsWithChildren } from 'react'; import { EventProxy, EventProxyProps } from '../components/EventProxy'; import { getElement } from '../utils'; export default function ( direction = 'parent' ) { const ref = useRef(null); const [, update] = React.useState(Symbol('__')); return [ getElement(ref.current, direction), React.useCallback(React.memo(function Spy(props: PropsWithChildren) { return ( { if (/^on[A-Z]+/.test(key) && typeof value !== 'function') { return { ...acc, [key]: () => update(Symbol('__')) }; } return { ...acc, [key]: value }; }, {} as EventProxyProps) )} /> ); }), []), ] as [T | null, (props: PropsWithChildren>) => JSX.Element]; };