forked from ryanseddon/react-frame-component
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
40 lines (36 loc) · 955 Bytes
/
index.js
File metadata and controls
40 lines (36 loc) · 955 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
var React = require('react');
var Frame = React.createClass({
propTypes: {
style: React.PropTypes.object,
head: React.PropTypes.node
},
render: function() {
return React.createElement('iframe', {
style: this.props.style,
head: this.props.head
});
},
componentDidMount: function() {
this.renderFrameContents();
},
renderFrameContents: function() {
var doc = this.getDOMNode().contentDocument;
if(doc && doc.readyState === 'complete') {
var contents = React.createElement('div',
undefined,
this.props.head,
this.props.children
);
React.render(contents, doc.body);
} else {
setTimeout(this.renderFrameContents, 0);
}
},
componentDidUpdate: function() {
this.renderFrameContents();
},
componentWillUnmount: function() {
React.unmountComponentAtNode(React.findDOMNode(this).contentDocument.body);
}
});
module.exports = Frame;