Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

186
Visualizações
running a script "<filename.min.js>" inside a react component

I am working on a small react project where I need to run a script whenever a certain component renders. The script is written in javascript and the filename is in the following format: .min.js

What I've tried so is,

 componentDidMount() {
  // Create a script in the DOM
  const script = document.createElement('script');
  // Assign properties to the script (src, id, data-brand, data-ref, asynv)
  script.src =
    'SRC_TO_MY_SCRIPT';
  script.id = 'SCRIPT_ID';
  script['data-brand'] = 'DATA_BRAND';
  script['data-ref'] = 'DATA_REF';
  script.async = true;
  // Append the script into the body of the react app
  this.div.appendChild(script);
}

and the div in returned in the render function of the class component the script is ought to run in. The thing is, I can see the script is loaded inside the div of the component but it never works. Is there any problem in the way I implement it?!

Thanks in advance.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda