0

I am looking to render a javascript file. I have included some library code (specifically leaflet.js), and I am using a local script to run after the page loads to render the id='map' div correctly. However, in my react component I am trying this and it is not working.

Specifically, it seems that even though "http://localhost:3000/src/MapRender.js" is at the correct location, it is not being found with a "Syntax error: unexpected token <" which I know means is a server 404. The file however is in the same folder as the component.

I am using a Helmet component to load the library script in the , however I would like this script to execute once the page loads so it can always find the correct div.

For context, I have created this app with create-react-app and have done basically nothing else besides create this Map component and add a Helmet component to the App component.

render() {
    return(
        <div id="map">
            <script type="text/javascript" src='MapRender.js'></script>
      </div>
    );
  }
antonig
  • 153
  • 1
  • 10
  • you can add it in componentdidMount() with create script tag – Shireesha Parampalli Feb 12 '19 at 08:43
  • Am I right in thinking that componentDidMount() will not be called when props changed triggering a rerender? For example, if I create this map with javascript based on a variable location as an argument, how do I force the script to run again? – antonig Feb 12 '19 at 21:14

0 Answers0