4

My use case is to integrate headwayapp.co to my React application.

I am trying to inject js via react component

The code of headwayapp is as follows to inject

<script src="//cdn.headwayapp.co/widget.js"></script>
<script>
  var config = {
    selector: ".CHANGE_THIS",
    account: "ACCOUNT_ID"
  };
  Headway.init(config);
</script>

Though I tried multiples way to inject code into the react.

In most cases I am not able to understand how to handle the line

Headway.init(config);

as react is not able to understand what is Headway variable ?

1
  • 1
    The component that contains that selector needs to mount before you intialize Commented Aug 24, 2019 at 21:29

1 Answer 1

1

To inject that code into your react app, you could simply place those script tags in your index.html file of your react app. Then you will be able to access the Headway variable in any of your react components like so: window.Headway

So basically, the code from http://cdn.headwayapp.co/widget.js will be loaded into your app at the place, where you put your script tags. That code is declaring Headway as a global variable, and global variables are living in the window object of your app. It does not matter if it is a react app or not.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.