react-use-iframe-content-height

A React hook to poll an iframe for it's content height. It will only work if the parent and the source of the iframe are on the same domain.

Usage no npm install needed!

<script type="module">
  import reactUseIframeContentHeight from 'https://cdn.skypack.dev/react-use-iframe-content-height';
</script>

README

react-use-iframe-content-height

A React hook to poll an iframe for it's content height. It will only work if the parent and the source of the iframe are on the same domain.

Usage:

function MyIframe() {
  const [iframeRef, iframeHeight] = useIframeContentHeight();

  return (
    <iframe ref={iframeRef} height={iframeHeight} width="100%" src="/content" />
  );
}