4 Ways to Add External JavaScript Files in React
React Hooks and other methods

Despite the wide availability of npm packages, at times, we might need to rely on a few external libraries that require us to import some JS files.
For features used across the application, we can simply add JS files to head using the <script> tag in our global index.html file.
However, for the features that are used in specific components, this makes no sense. Since React doesn’t support the <script> tag in Component, here are a few ways of appending JS files to specific components.
React-script-tag
This is the easiest way of loading JS files for a beginner.
React-script-tag is an npm package that provides a React <script> tag that supports universal rendering. All standard <script> attributes like async, src, type, and defer are supported, including onLoad and onError callbacks.
import ScriptTag from 'react-script-tag';const Demo = props => (
<ScriptTag type="text/javascript" src="/path/to/resource.js" />
)We also have an isHydrating flag, which is a boolean value. It defaults to false and must be true if the client is hydrate()ing the server render.
You can read more about hydrate() in the React docs.
React Helmet
Helmet is a React component that manages all your changes to the document head. It is another simple, beginner-friendly package that supports both server-side and client-side rendering.
Helmet takes plain HTML tags and outputs plain HTML tags.






