google-map-react / old-examples

Examples for google-map-react component.
http://google-map-react.github.io/google-map-react/map/main/
357 stars 316 forks source link

marker event does not fire in `map` #40

Closed rostgoat closed 4 years ago

rostgoat commented 4 years ago

Cannot for the life of me get this event of to fire on the child Marker anyone know why?

I have tried using onClick, using bind and onChildClick but nothing works

onSelectMarker = marker => e => {
    e.preventDefault();
    console.log("clicked");
  };
  render() {
    const data = this.props.searchedResponse;

    const Markers = data
      ? data.data.records.map(marker => {
          return (
            <Marker
              key={marker.recordid}
              lat={marker.fields.geom.coordinates[1]}
              lng={marker.fields.geom.coordinates[0]}
              onChildClick={() => this.onSelectMarker(marker)}
            />
          );
        })
      : null;
    return (
      <div className="map">
        <GoogleMapReact
          center={this.state.center}
          zoom={this.state.zoom}
          bootstrapURLKeys={{
            key: process.env.REACT_APP_GOOGLE_KEY
          }}
        >
          {Markers}
        </GoogleMapReact>
      </div>
    );
  }
}