Created
December 20, 2018 01:08
-
-
Save 0xf0f0f0/51ffc851c9a68714f623869b7c7fee0e to your computer and use it in GitHub Desktop.
React iframe component
This file contains hidden or 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
| /* | |
| INIT: ensure Babel/Eslint/Flow is configured for ES Class Fields & Static Properties | |
| JSX USAGE: <Iframe src='http://web.site' onLoad={myOnloadFunction}/> | |
| */ | |
| import React, { Component, PropTypes } from 'react' | |
| import ReactDOM from 'react-dom' | |
| class Iframe extends Component { | |
| static propTypes: Object = { | |
| src: PropTypes.string.isRequired, | |
| onLoad: PropTypes.func, | |
| } | |
| componentDidMount () { | |
| let iframe = ReactDOM.findDOMNode(this.refs.iframe) | |
| iframe.addEventListener('load', this.props.onLoad); | |
| } | |
| render () { | |
| const iframeStyle = { | |
| width: '100%', | |
| height: '100%', | |
| border: '0', | |
| position: 'absolute', | |
| } | |
| return ( | |
| <iframe | |
| ref="iframe" | |
| {...this.props} | |
| frameBorder={'0'} | |
| width={'100%'} | |
| height={'100%'} | |
| style={iframeStyle} | |
| /> | |
| ) | |
| } | |
| } | |
| export default Iframe |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment