1

For some reason I don't want to use npm or Atmosphere Google Maps packages in my Meteor app. And try to use Google maps directly. So, inside a React Component I have the following render method and onMapLoaded() class method:

render(){
    return(
        <div ref={el => (this.instance = el)}>
            <p>Map</p>
            <script async defer
                    src={"https://maps.googleapis.com/maps/api/js?key=" 
                    + GoogleMapsKey 
                    + "&callback=" + ????}>
                </script>
            </div>
        );
    }

Can't figure out, how to pass as the callback this.onMapLoaded function ref, not it's value.

It's no dublicate, because there are no explanation how pass React Component' method to script as a paramether.

Dmitry
  • 727
  • 1
  • 8
  • 34
  • Possible duplicate of [Adding script tag to React/JSX](https://stackoverflow.com/questions/34424845/adding-script-tag-to-react-jsx) – azium Dec 28 '17 at 19:01
  • also.. I would highly recommend not using `callback` parameter and instead use the API methods provided by google maps `new google.maps.Map` for instance https://developers.google.com/maps/documentation/javascript/tutorial – azium Dec 28 '17 at 19:04
  • I read this question and answers. As I understand, I have to include script first. After it I can use google.maps.Map. What I plan to do inside onMapLoaded method. That is why I need pass it as a callback. – Dmitry Dec 28 '17 at 19:08
  • And I'd like to unerstand common approach, because passing function ref as a param is a question, not a particular google map script. – Dmitry Dec 28 '17 at 19:15

0 Answers0