Categories
React Answers

How to Call External JavaScript Function from React Components?

Spread the love

Sometimes, we want to call external JavaScript functions from React components.

In this article, we’ll look at how to call external JavaScript functions from React components.

Call External JavaScript Function from React Components

We can call external JavaScript functions from React components.

If we have something like:

<script>
  function test(){
    alert('hello world');
  }
</script>

Then we created a global function that we can call in our React components.

Inside it, we write:

componentWillMount() {
  window.test();
}

Conclusion

We can call external JavaScript functions from React components.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *