Skip to content

Instantly share code, notes, and snippets.

@momendo
Forked from msmfsd/Iframe.js
Last active January 3, 2019 05:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save momendo/0742994ec0e6eb5ae5fd084bd99c85e7 to your computer and use it in GitHub Desktop.
Save momendo/0742994ec0e6eb5ae5fd084bd99c85e7 to your computer and use it in GitHub Desktop.
React iframe component
/*
Prop-types was broken out of React in 15.5
JSX USAGE: <Iframe src='http://web.site' onLoad={myOnloadFunction}/>
*/
import React, { Component } from 'react'
import ReactDOM from 'react-dom'
import PropTypes from 'prop-types'
class Iframe extends Component {
static propTypes: Object = {
src: PropTypes.string.isRequired,
onLoad: PropTypes.func,
}
componentDidMount () {
let iframe = ReactDOM.findDOMNode(this.refs.iframe)
iframe.onload = () => this.props.onLoad // workaround Chrome event bug firing twice
}
componentWillUnmount() {
let iframe = ReactDOM.findDOMNode(this.refs.iframe)
iframe.onload = null
}
shouldComponentUpdate() {
return false;
}
render () {
const iframeStyle = {
width: '100%',
height: '100%',
border: '0'
}
return (
<iframe
ref="iframe"
{...this.props}
frameBorder={'0'}
style={iframeStyle}
/>
)
}
}
export default Iframe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment