I bought a html template with scripts and I want to create a react app. I add script to index.html of my react app like this:
<script
async
type="text/javascript"
src="%PUBLIC_URL%/assets/js/vendor/modernizr-2.8.3.min.js"
></script>
<script
async
type="text/javascript"
src="%PUBLIC_URL%/assets/js/vendor/jquery.min.js"
></script>
<script
async
type="text/javascript"
src="%PUBLIC_URL%/assets/js/popper.min.js"
></script>
<script
async
type="text/javascript"
src="%PUBLIC_URL%/assets/js/main.js"
></script>
Why it doesn't always work? And it works only with async.
But if i try to use libraries like react-helmet or useEffect or import js file in index.js i get bunch of errors.
useEffect(() => {
const script = document.createElement('script');
script.src = "https://use.typekit.net/foobar.js";
script.async = true;
document.body.appendChild(script);
return () => {
document.body.removeChild(script);
}
}, []);
Errors:
src/assets/js/vendor/jquery.min.js
Line 2:1: Expected an assignment or function call and instead saw an expression no-unused-expressions
Line 2:1140: Expected an assignment or function call and instead saw an expression no-unused-expressions
Line 2:2095: Expected an assignment or function call and instead saw an expression no-unused-expressions
Line 2:5737: Expected an assignment or function call and instead saw an expression no-unused-expressions
Line 2:6613: Expected an assignment or function call and instead saw an expression no-unused-expressions
Line 2:6734: Expected an assignment or function call and instead saw an expression