0

I would like to execute embeded Javascript inside a React Component. The code is loaded with the page from an Express NodeJs server. It is running fine on a single page inside a browser.

<script type="text/javascript"
    src="http://localhost:3000/embed.js"
    data-schnack-host="//localhost:3000"
    data-schnack-slug="foofee"
    data-schnack-target="#my-comments"
    data-schnack-partial-reply="Answer to this comment"
    data-schnack-partial-post-comment="Write your comment here."        
></script>
Comments:
<div id="my-comments"></div>

But I need to integrate this into the render() method of a React Component. I've tried everything like include the "embed.js" inside the "dist" folder, the Javascript code is loaded but not executed. The console is showing no warnings or errors, the script is just ignored.

I'm sure it is not a cross domain/checkOrigin problem because it is running like a charm inside an external browser.

Did I miss something ?

  • 1
    Possible duplicate of [Adding script tag to React/JSX](https://stackoverflow.com/questions/34424845/adding-script-tag-to-react-jsx) – Matt Lishman Jan 21 '19 at 11:09
  • Try getting rid of this line `data-schnack-host="//localhost:3000"`. It seems like it is the same host as the src so it should be redundant, it also seems broken without the protocol as it looks like a file path without it. Remember electron can load files from the file system so it could be that. – justin.m.chase Jan 21 '19 at 17:48

0 Answers0