Last active
June 8, 2018 18:03
-
-
Save zachberry/fe57deaaf1b06c9e2d239dd8661e4e9d to your computer and use it in GitHub Desktop.
Get HTML from a React component and inject it into an iframe
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
class TestPage extends React.Component { | |
render() { | |
return ( | |
<body>...</body> | |
) | |
} | |
} | |
class SomeComponent extends React.Component { | |
injectTestPage() { | |
let div = document.createElement('div') | |
ReactDOM.render(<TestPage />, div) | |
this.refs.iframe.contentDocument.body.outerHTML = div.outerHTML | |
} | |
render() { | |
return ( | |
<div> | |
<iframe ref="iframe" /> | |
</div> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment