Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

146
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda