diff options
| author | Rafi Zadanly <zadanlyr@gmail.com> | 2023-03-31 11:17:55 +0700 |
|---|---|---|
| committer | Rafi Zadanly <zadanlyr@gmail.com> | 2023-03-31 11:17:55 +0700 |
| commit | 092dc7fc49246580023a8b97101d51845c81bf04 (patch) | |
| tree | 089121b3c6cf46429411ae6edc6c4babfebe0e0d /src/lib/iframe | |
| parent | f23d32a4b8402904e8daa7b906c03a64104ed253 (diff) | |
iframe content
Diffstat (limited to 'src/lib/iframe')
| -rw-r--r-- | src/lib/iframe/components/IframeContent.jsx | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/lib/iframe/components/IframeContent.jsx b/src/lib/iframe/components/IframeContent.jsx new file mode 100644 index 00000000..52f2a26e --- /dev/null +++ b/src/lib/iframe/components/IframeContent.jsx @@ -0,0 +1,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 |
