import type { RefObject } from 'react' ; import type { Fiber } from 'react-reconciler' ; import { useEffect , useRef } from 'react' ; import { ParentFiber } from './parentFiber' ; import { getFiberFromElementInstance } from '../fiber/getFiber' ; import { invariant } from '../invariant' ; param findFiber returns export function useParent < T extends Node > ( ref , findFiber ? ) { const parentRef = useRef < ParentFiber | null > ( null ) ; if ( parentRef . current === null ) { parentRef . current = new ParentFiber ( ) ; } const parent = parentRef . current ; parent . setFinder ( findFiber ) ; useEffect ( ( ) => { invariant ( ref . current !== null && ref . current !== undefined , 'You must set the ref returned by the useParent hook.' ) ; parent . setFiber ( getFiberFromElementInstance < T > ( ref . current ) ) ; return ( ) : void => { parent . clear ( ) ; } ; } , [ ] ) ; return parent ; }