I'm trying to use root because I have scrollable modal as a viewport:
const parentRef = useRef(null);
return (
<Parent ref={parentRef}>
{someList.map((item) => (
<RenderIfVisible root={parentRef.current}>
{item}
</RenderIfVisible>
)}
</Parent>
);
It doesn't work right - it seems Observer's root is still document. I think this is happening because ref's current is not immediately available and by the time Observer is created it's still null.
If I do it this way it seems to work right:
{parentRef.current && <RenderIfVisible root={parentRef.current}>
{item}
</RenderIfVisible>}
Is it correct? Is it a good practice? Should RenderIfVisible track root's availability?
I'm trying to use root because I have scrollable modal as a viewport:
It doesn't work right - it seems Observer's
rootis still document. I think this is happening because ref'scurrentis not immediately available and by the time Observer is created it's still null.If I do it this way it seems to work right:
Is it correct? Is it a good practice? Should RenderIfVisible track root's availability?