p5.js-web-editor/shared/components/Preview/Preview.jsx

32 lines
668 B
React
Raw Normal View History

2016-05-05 21:48:26 +00:00
import React from 'react';
import ReactDOM from 'react-dom';
2016-05-05 21:48:26 +00:00
class Preview extends React.Component {
componentDidMount() {
this.renderFrameContents();
}
renderFrameContents() {
let doc = ReactDOM.findDOMNode(this).contentDocument;
if(doc.readyState === 'complete') {
ReactDOM.render(this.props.children, doc.body);
} else {
setTimeout(this.renderFrameContents, 0);
}
}
componentDidUpdate() {
this.renderFrameContents();
}
componentWillUnmount() {
React.unmountComponentAtNode(this.getDOMNode().contentDocument.body);
}
2016-05-05 21:48:26 +00:00
render() {
return <iframe sandbox="allow-same-origin"></iframe>;
2016-05-05 21:48:26 +00:00
}
}
export default Preview;