I have a small problem. After requesting a data from a service I got an iframe code in response.
You can use property dangerouslySetInnerHTML, like this
const Component = React.createClass({
iframe: function () {
return {
__html: this.props.iframe
}
},
render: function() {
return (
);
}
});
const iframe = '';
ReactDOM.render(
,
document.getElementById('container')
);
also, you can copy all attributes from the string(based on the question, you get iframe as a string from a server) which contains tag and pass it to new tag, like that
/**
* getAttrs
* returns all attributes from TAG string
* @return Object
*/
const getAttrs = (iframeTag) => {
var doc = document.createElement('div');
doc.innerHTML = iframeTag;
const iframe = doc.getElementsByTagName('iframe')[0];
return [].slice
.call(iframe.attributes)
.reduce((attrs, element) => {
attrs[element.name] = element.value;
return attrs;
}, {});
}
const Component = React.createClass({
render: function() {
return (
);
}
});
const iframe = '';
ReactDOM.render(
,
document.getElementById('container')
);