I have a landing page and some about, faq, tnc, etc pages. When I navigate (using react-router v6) from landing page to another and come back, the useEffect executes even though I have given empty dependency array.
useEffect(() => {
const script = document.createElement("script");
script.async = true;
script.type = "module";
script.src = "scripts/animation.script.js";
document.body.appendChild(script);
console.log("running");
}, []);
I also tried passing a dependency which do not change like this..
const doNotLoadLandingAnimation = true;
useEffect(() => {
const script = document.createElement("script");
script.async = true;
script.type = "module";
script.src = "scripts/animation.script.js";
document.body.appendChild(script);
console.log("running");
}, [doNotLoadLandingAnimation]);
But still.. useEffect executes everytime the page is visited.