import React, {PureComponent, PropTypes} from 'react'; class ResponseWebview extends PureComponent { _handleSetWebviewRef = n => this._webview = n; _handleDOMReady = () => { this._webview.removeEventListener('dom-ready', this._handleDOMReady); this._setBody(); }; _setBody () { const {body, contentType, url} = this.props; const newBody = body.replace('', ``); this._webview.loadURL(`data:${contentType},${encodeURIComponent(newBody)}`); } componentDidUpdate () { this._setBody(); } componentDidMount () { this._webview.addEventListener('dom-ready', this._handleDOMReady); } render () { return ( ); } } ResponseWebview.propTypes = { body: PropTypes.string.isRequired, contentType: PropTypes.string.isRequired, url: PropTypes.string.isRequired }; export default ResponseWebview;