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

207
Vistas
how do i use script tags in a function component from react

I am using React. I want to work with hooks and because I am using a custom theme I need to use many CDNs. I want to use custom script tags for my functional components. I wrote a method with useEffect but it doesn't work properly. How do I access the js files in my Assets folder on each page?

e.g. SignUpPage:

import React, { useState } from "react";
import axios from "axios";
import useScript from "../../hooks/useScript";

import "../../assets/css/style.bundle.css";
import "../../assets/css/pages/wizard/wizard-5.css";
import "../../assets/plugins/custom/prismjs/prismjs.bundle.css";
import "../../assets/plugins/global/plugins.bundle.css";

function SignUpPage() {
  useScript("/src/assets/plugins/global/js/plugins.bundle");
...
}

useScript.js

import { useEffect } from "react";

const useScript = (url) => {
  useEffect(() => {
    const script = document.createElement("script");

    script.src = url;
    script.async = t;

    document.body.appendChild(script);

    return () => {
      document.body.removeChild(script);
    };
  }, [url]);
};

export default useScript;

I also tried using the React-Helmet and React-Script-Tag packages. But I could not. I also put the script js files in the public folder and called index.html. This time they worked. But since I have too many script js files, it seems like it is not possible for me to do a general operation.

about 4 years ago · Juan Pablo Isaza
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