import { useEffect, useRef } from "react";
const useAttach = (target)=>{
    const oldTargetRef = useRef(null);
    useEffect(()=>{
        if (oldTargetRef.current && target !== oldTargetRef.current) oldTargetRef.current.onUnmount();
        oldTargetRef.current = target;
        target.onMount();
        return ()=>{
            target.onUnmount();
        };
    }, [
        target
    ]);
    return target;
};
export { useAttach };
