Skip to content

Instantly share code, notes, and snippets.

@lynndylanhurley
Last active March 18, 2020 17:37
Show Gist options
  • Save lynndylanhurley/f2e2a48dd3b03a36b6a09ba62fdb63ca to your computer and use it in GitHub Desktop.
Save lynndylanhurley/f2e2a48dd3b03a36b6a09ba62fdb63ca to your computer and use it in GitHub Desktop.
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