summaryrefslogtreecommitdiff
path: root/src/lib/iframe/components/IframeContent.jsx
blob: 52f2a26e02c834b45260feb615077c1350cc714d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { useEffect, useRef, useState } from 'react'

const IframeContent = ({ url }) => {
  const [iframeLoaded, setIframeLoaded] = useState(false)
  const [iframe, setIframe] = useState(null)
  const iframeRef = useRef(null)

  useEffect(() => {
    if (iframeLoaded) {
      setIframe({
        height: document.querySelector('main').offsetHeight
      })
    }
  }, [iframeLoaded])

  return (
    <div className='mx-auto container h-full'>
      <iframe
        ref={iframeRef}
        src={url}
        width='100%'
        seamless
        style={{ height: iframe?.height || 0 }}
        onLoad={() => setIframeLoaded(true)}
      />
    </div>
  )
}

export default IframeContent