-
-
Save momendo/0742994ec0e6eb5ae5fd084bd99c85e7 to your computer and use it in GitHub Desktop.
React iframe component
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
/* | |
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