0
function createMarkup(str) {
return { __html: str };
}
function GraphicLarge({ HTMLData }) {
return (
<div className="graphic graphic--lg">
{ isFetching ? <div dangerouslySetInnerHTML={createMarkup(HTMLData)} /> : <Loading /> }
</div>
);
}
<!--
./statics/html/grafico1.html
# HTML que preciso inserir
# Eu busco esse HTML com uma requisição.
-->
<link href="https:/example.br/css/main.css" rel="stylesheet" type="text/css">
<div id="grafico">
<img src="https:/example.br/img/1.svg" alt="Imagem" />
<h1>Conteudo do gráfico</h1>
</div><!-- /#grafico -->
<script src="https:/example.br/js/libs/graph.js" type="text/javascript"></script>
<script src="https:/example.br/js/bundle.js" type="text/javascript"></script>
I’m doing a task that searches for a file .html, for example: A piece of a graph. The thing is, the files JS html is not executed (not even loaded) when html is inserted into the DOM by the function dangerouslySetInnerHTML . The other statics (CSS, Images and fonts) are loaded without any problem.
The
dangerouslySetInnerHTML
is to avoid the type of code you are trying to use. You should do it another way. Where do these JS files come from? Are you using webpack?– Sergio
So that’s another way I need to learn. I use the webpack yes. I’ll try to put an example in the description. Thanks for the answer.
– Wérick Vieira
It looks like an alternative is to use this guy: https://developer.mozilla.org/en-US/docs/Web/API/range/createContextualFragment
– Wérick Vieira