import ScrollIntoViewTargetElement from './ScrollIntoViewTargetElement'; const React = window.React; const {Fragment, useRef, useState, useEffect} = React; const ReactDOM = window.ReactDOM; export default function ScrollIntoViewCaseComplex({ caseInViewport, scrollContainerRef, }) { const [didMount, setDidMount] = useState(false); // Hack to portal child into the scroll container // after the first render. This is to simulate a case where // an item is portaled into another scroll container. useEffect(() => { if (!didMount) { setDidMount(true); } }, []); return ( {caseInViewport && ( )} {didMount && ReactDOM.createPortal( , scrollContainerRef.current )} {caseInViewport && ( )} ); }