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

148
Visualizações
Function not working in app.js but in index.html working library reactjs

I'm having a problem when using a function from the New Relic library,

Can try with codesandbox

If I use this function in public/index.html (command in codesandbox) it works:

screenshot in inspect element working :

enter image description here

well the problem is if I create my own helpers function and create in app.js it doesn't work

below is the app.js file :

import { useEffect } from "react";
import { newRelicConfig } from "./newRelic";
import "./styles.css";

export default function App() {
  useEffect(() => {
    let script = document.createElement("script");
    script.type = "text/jsx";
    script.innerHTML = newRelicConfig(
      "3277692",
      "3277692",
      "NRJS-93eea892ddd7204acfd",
      "1091749869"
    );
    document.body.appendChild(script);
  }, []);
  return (
    <div className="App">
      <h1>New Relic</h1>
      <h2>Start editing to see some magic happen!</h2>
    </div>
  );
}

in file ./newRelic function newRelicConfig

the function of NRJS does not exist :

enter image description here

How to work around a function in app.js like with index.html ?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I'm getting a syntax error while trying to execute your function in newRelix.jsx, so first of all double check the function.

That being said, adding a javascript function in a script tag to your HTML document is not the same as executing that function. You could try adding it as a self invoking function. Also note the the type should be text/javascript (not text/jsx):

useEffect(() => {
    let functionBody = newRelicConfig(...); // omitting params here, as they're possibly sensitive
    let script = document.createElement("script");
    script.type = "text/javascript";
    script.innerHTML = `(function(){${functionBody}})();`;
    document.body.appendChild(script);
  }, []);
about 4 years ago · Juan Pablo Isaza Relatório
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