我试图让GoogleMapGazi使用'props=>‘来访问我的类GoogleMaps的属性,但是我做不到。我已经通过父组件将lat和lng props传递给了类。这是我的代码,任何帮助都会很好!
const GoogleMapGazi = withGoogleMap(props => (
<GoogleMap
defaultCenter={{ lat: 25.804281, lng: -80.1903893 }}
defaultZoom={15}
>
<Marker position={{ lat: props.lat, lng: props.lng }} />
</GoogleMap>
));
class GoogleMaps extends Component {
render() {
return (
<div>
<GoogleMapGazi
containerElement={<div style={{ height: `500px`, width: "600px" }} />}
mapElement={<div style={{ height: `100%` }} />}
/>
</div>
);
}
}
export default GoogleMaps;发布于 2018-08-03 01:58:29
您必须将GoogleMaps组件中的道具传递下去。
您可以显式地向下传递lat和lng属性,也可以使用扩展语法来向下传递所有属性。
class GoogleMaps extends Component {
render() {
return (
<div>
<GoogleMapGazi
containerElement={<div style={{ height: `500px`, width: "600px" }} />}
mapElement={<div style={{ height: `100%` }} />}
{...this.props}
/>
</div>
);
}
}https://stackoverflow.com/questions/51659581
复制相似问题