将onClick添加到自定义组件

时间:2019-03-09 18:04:34

标签: reactjs

<GoogleMapReact
  bootstrapURLKeys={{ key: this.props.key }}
  defaultCenter={this.props.center}
  defaultZoom={this.props.zoom}
>
  {markers.map((marker, index) => {
    return (
      <Marker
        key={index}
        lat={marker.lat}
        lng={marker.lng}
        name={marker.name}
        status={marker.status}
        onClick={this.onClick}
      />
    );
  })}
  <Marker lat={46.73023} lng={-117.003782} name={"Moscow Alehouse"} />
</GoogleMapReact>

我目前正在使用React Google Maps将地图渲染到屏幕上。我添加了一个名为Marker的自定义组件,它是带有某些样式的SVG图像。我的问题是如何向这些自定义组件添加onClick。我不能将它们包装在div中。我希望它们在用户单击其中之一时突出显示。

0 个答案:

没有答案
相关问题