I have a small problem. After requesting a data from a service I got an iframe code in response.
<iframe src="https://www.example.com/show?data..." width="540" height="450"></iframe>
I would like to pass this in as a props to my modal component and display it but when I simply {this.props.iframe}
it in the render function it is obviously displaying it as a string.
What is the base way to display it as html in react?
You can use property
dangerouslySetInnerHTML
, like thisalso, you can copy all attributes from the string(based on the question, you get iframe as a string from a server) which contains
<iframe>
tag and pass it to new<iframe>
tag, like thatIf you don't want to use dangerouslySetInnerHTML then you can use the below mentioned solution
here live demo is available Demo