Last active
March 18, 2020 17:37
-
-
Save lynndylanhurley/f2e2a48dd3b03a36b6a09ba62fdb63ca to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useEffect, useState } from 'react'; | |
import { get } from 'lodash'; | |
function IframeTest() { | |
const [size, setSize] = useState({}); | |
function receiveMessage(message) { | |
const { data } = message; | |
if (get(data, 'type') === 'resize') { | |
const { width, height } = data; | |
setSize({ width, height }); | |
} | |
} | |
if (typeof window !== 'undefined') { | |
useEffect(() => { | |
window.addEventListener('message', receiveMessage, false); | |
}, []); | |
} | |
return ( | |
<iframe | |
style={{ borderBottom: 'dotted red 6px' }} | |
title="test" | |
src="/" | |
width="100%" | |
height={size.height} | |
/> | |
); | |
} | |
export default IframeTest; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment