Javascript prop`loadingElement`在`withScriptjs(withGoogleMap(Component))
我得到了这个错误:“失败的道具类型:道具Javascript prop`loadingElement`在`withScriptjs(withGoogleMap(Component)),javascript,reactjs,google-maps,google-maps-api-3,Javascript,Reactjs,Google Maps,Google Maps Api 3,我得到了这个错误:“失败的道具类型:道具加载元素在中用scriptjs(带谷歌地图(组件))标记为必需,但其值是未定义的。 在withScriptjs中(withGoogleMap(组件))” My Map.js文件: import React, {Component} from "react"; import { withScriptjs, withGoogleMap, GoogleMap, Marker, } from "react-google-maps"; co
加载元素
在中用scriptjs(带谷歌地图(组件))
标记为必需,但其值是未定义的
。
在withScriptjs中(withGoogleMap(组件))”
My Map.js文件:
import React, {Component} from "react";
import {
withScriptjs,
withGoogleMap,
GoogleMap,
Marker,
} from "react-google-maps";
const MapWithAMarker = withScriptjs(withGoogleMap(props =>
<GoogleMap
defaultZoom={8}
defaultCenter={{ lat: -34.397, lng: 150.644 }}
>
<Marker
position={{ lat: -34.397, lng: 150.644 }}
/>
</GoogleMap>
));
<MapWithAMarker
googleMapURL="https://maps.googleapis.com/maps/api/js?key=AIzaSyAIdFegRbfOurYRvDN8oQNJRmpKgIj48ZY&libraries=geometry,drawing,places"
loadingElement={<div style={{ height: `100%` }} />}
containerElement={<div style={{ height: `100%` }} />}
mapElement={<div style={{ height: `100%` }} />}
/>
export default MapWithAMarker;
import React,{Component}来自“React”;
进口{
用ScriptJS,
用谷歌地图,
谷歌地图,
标记,
}从“谷歌地图反应”;
const MapWithAMarker=withScriptjs(withGoogleMap(props=>
));
导出默认MapWithAMarker;
我将这个文件导入到我的另一个js文件中,并将
<div style={{width:400, hight:300, background:"red"}}>
<MapWithAMarker />
</div>
就像这里面的js。我得到了上面提到的错误。这就是我在当前项目中如何称呼它的,它工作得很好。也许这会给你指明正确的方向
const EmptyMap = compose(
withProps({
googleMapURL: "https://maps.googleapis.com/maps/api/js?key=APIKEY&v=3.exp&libraries=geometry,drawing,places",
loadingElement: <div style={{ height: `100%` }} />,
containerElement: <div style={{ height: `1000px`, display: 'none' }} />,
mapElement: <div style={{ height: `100%` }} />,
}),
withScriptjs,
withGoogleMap
)((props) =>
<GoogleMap
defaultZoom={9}
defaultCenter={{ lat: parseFloat(props.userLat), lng: parseFloat(props.userLng) }}
>
</GoogleMap>
);
const EmptyMap=compose(
用道具({
谷歌地图网址:https://maps.googleapis.com/maps/api/js?key=APIKEY&v=3.exp&libraries=geometry,图纸,位置“,
加载元素:,
集装箱运输:,
mapElement:,
}),
用ScriptJS,
用谷歌地图
)((道具)=>
);
,此处您传递的道具可能不是预期的方式。请检查一下文档。文档中的顺序如下@RiyaKapuria从“重新组合”导入{compose,withProps},该错误不应阻止贴图渲染。失败的GET请求不会停止页面的呈现。你只是少了一个favicon,这与地图无关。地图现在有用吗?