Setting external HTML in react components

418 views Asked by At

I am working on a website that I want to embed an external HTML to my web page. So I tried the following ways using iframe but it only shows me a blank page with no content

import React from 'react';

function MapVisualization(props) {
    return(
        <div>                                                                                                                                                              
            <iframe src="https://voyagerwsh.shinyapps.io/USMapWithCountyPolygon/?_ga=2.183050790.160516643.1596758294-1394498961.1595634152" style="border: none; width: 1\
00%; height: 850px" frameborder="0"></iframe>                                                                                                                              
        </div>
    );
}
export default MapVisualization;

I also used another way of implementing innerHTML:

import React from 'react';

function MapVisualization(prop) {
    return(
        <div dangerouslySetInnerHTML = {{ __html: 'https://voyagerwsh.shinyapps.io/USMapWithCountyPolygon/?_ga=2.183050790.160516643.1596758294-1394498961.1595634152'}} />
    );
}
export default MapVisualization;

But the result looks like this: InnerHTML result Does anyone know how to fix this? Thanks!

1

There are 1 answers

1
Daniil Loban On BEST ANSWER

style was written by wrong way, style must be object

import React from 'react';

function MapVisualization(props) {
    return(
        <div>                                                                                                                                                              
          <iframe src="https://voyagerwsh.shinyapps.io/USMapWithCountyPolygon/?_ga=2.183050790.160516643.1596758294-1394498961.1595634152"
             style={{ border: 'none',
             width: '100%', 
             height: 850,
             frameborder:0}}>
          </iframe>                                                                                                                              
        </div>
    );
}
export default MapVisualization;