简体   繁体   English

我如何将无状态映射组件转换为React组件

[英]How can i convert stateless map component into react component

My MyMapComponent is the stateless component, it was used the compose and with props and props. MyMyMapComponent是无状态组件,它与props和props一起使用。 How can i convert into react component with this? 我该如何转换为React组件? My requirement is to place the code into render return function directly. 我的要求是将代码直接放入渲染返回函数中。

 const MyMapComponent = compose( withProps({ googleMapURL: "https://maps.googleapis.com/maps/api/js?key=AIzaSyB-lALSE8L0zgfk0vdt73gNTsfalkAggwY&v=3.exp&libraries=geometry,drawing,places", loadingElement: <div style={{ height: "100%" }} />, containerElement: <div style={{width:"100%", height: ht,}} />, mapElement: <div style={{ height: "100%"}} /> }), withScriptjs, withGoogleMap )(props => ( <GoogleMap defaultZoom={10} defaultCenter={{ lat: 32.6804468, lng: -97.0827933 }}> <Marker onClick={props.onMarkerClick} position={{ lat: 32.6804468, lng: -97.0827933 }} /> <Marker onClick={props.onMarkerClick1} position={{ lat: 32.7020541, lng: -97.2755012 }} /> <Marker onClick={props.onMarkerClick} position={{ lat: 32.5872886, lng: -97.0258724 }} /> <Marker onClick={props.onMarkerClick1} position={{ lat: 35.2962839, lng: -98.2031782 }} /> </GoogleMap> )); 

I'm not sure about your requirement. 我不确定您的要求。 If you only need the render function, then stateless function is probably the correct way to go. 如果只需要render函数,那么无状态函数可能是正确的选择。

However, this will most probably be what you need: 但是,这很可能是您需要的:

https://codesandbox.io/s/wo837p9z5 https://codesandbox.io/s/wo837p9z5

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM