const [contentRef, setContentRef] = useState<any>(null);
const doc = contentRef?.contentWindow?.document;
const mountNode = doc?.body;
const insertionTarget = doc?.head;
return (
<Box
as="iframe"
ref={setContentRef}
{...props}
>
{* some code here *}
</Box>
Recently while working with iframes and @emotion/react i came across this code but I am not sure about using useState for accessing DOM node. when I console.log(contentRef) it returns iframe DOM node.
Can someone please explain how is this working and how it is different from using useRef().