0

I'm trying to add the following script

<script src="//ad.lomadee.com/banners/script.js?sourceId=37645311&dimension=27&height=90&width=970&method=0" type="text/javascript" language="javascript"></script>

As this is an advertising script, I need to include it in several places in my app. For that reason, I'm not putting it in the HTML.

I would like to create a react component that can be called multiple times in different places.

  • 1
    Does this answer your question? [Adding script tag to React/JSX](https://stackoverflow.com/questions/34424845/adding-script-tag-to-react-jsx) – Konrad Aug 29 '22 at 15:16
  • why not just add it to your html master template? – Mike 'Pomax' Kamermans Aug 29 '22 at 15:21
  • @Mike'Pomax'Kamermans seems like this is an ad script that replaces itself with the actual ad – Konrad Aug 29 '22 at 15:23
  • 1
    That's something Alexandre gets to explain, but in the absence of an explanation I'd assume this injects a new DOM note, not replaces the script node (which would be rather strange, given that script nodes typically live in the document head element) – Mike 'Pomax' Kamermans Aug 29 '22 at 15:31

1 Answers1

0

There are 2 approach to include external scripts in react.js app.

  1. Using react-script-tag Package
  2. Using react-helmet Package

Please look at the following blog.

https://www.geeksforgeeks.org/how-to-include-an-external-javascript-library-to-reactjs/#:~:text=Installation%3A%20Open%20a%20terminal%20inside,react%2Dscript%2Dtag%20Package.&text=Import%20'ScriptTag'%20component%3A%20Import,to%20add%20the%20script%20tag.

F.E
  • 688
  • 6
  • 10