Skip to content

Instantly share code, notes, and snippets.

@nguyenvanhaivn
Forked from iest/BzIframe.js
Created May 28, 2019 07:39
Show Gist options
  • Select an option

  • Save nguyenvanhaivn/e1496351e8994c9ca8c506306e84bd27 to your computer and use it in GitHub Desktop.

Select an option

Save nguyenvanhaivn/e1496351e8994c9ca8c506306e84bd27 to your computer and use it in GitHub Desktop.
Basic react iframe with onLoad handler
'use strict';
var React = require('react');
var BzIframe = React.createClass({
propTypes: {
src: React.PropTypes.string.isRequired,
onLoad: React.PropTypes.func
},
componentDidMount: function() {
this.refs.iframe.getDOMNode().addEventListener('load', this.props.onLoad);
},
render: function() {
return <iframe ref="iframe" {...this.props}/>;
}
});
module.exports = BzIframe;
var Example = React.createClass({
getInitialState: function() {
return {
isLoading: true
};
},
render: function() {
var classes = cx({
'is-loading': this.state.isLoading // Hide `is-loading` with CSS
});
return (
{this.state.isLoading ?
<p>Loading... A spinner would probably be nice here</p>
:null
}
<BzIframe className={classes} onLoad={this._iframeLoaded} src="http://link-to-somewhere"/>
</div>
</DocumentTitle>
);
},
_iframeLoaded: function() {
this.setState({
isLoading: false
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment