I had js files under public folder i want to include these js files in to react components which are under src component folder in react create application?
Please read Using the public Folder.
In general we recommend installing packages from npm and using import
to access them from the source. But if you must use a prebuilt JS file that you don’t want to import, you can add it to the public
folder (for example, public/mylib.js
) and then add this to public/index.html
:
Then you can access the global variable from your app, for example:
const mylib = window.mylib;
And then use it.
Hope this helps!