Adding external javascript script to React failed!
Author: Mulligan81Created Jan 10, 2022Updated May 19, 2026
I'd like to include & run some `js` file in the `React` using `Helmet` component. Here is the simple code:
*index.js:*
import React from "react";
import ReactDOM from "react-dom";
import { Helmet } from "react-helmet";
import "./styles.css";
function App() {
console.log("op");
return (
);
}
and ultra simple `js` script to include & run:
*hello.js:*
console.log("opl882...")
document.body.style.backgroundColor = "red";
But the script seems NOT to work! - i have no console output and/or background color changed. What's odd when I use the `js` code as an inline code like:
it works!
Why doesn't the external `js` file work?
Hellok CodeSandbox
Start editing to see some magic happen!
Source: nfl/react-helmet