刚刚将react-leaflet
版本从1.9.1更新到2.0.0,并收到一个奇怪的错误:
Uncaught Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.
Check the render method of `Map`.
我至少需要将react-leaflet
升级到版本2,这样我才能在react-leaflet
中使用withLeaflet
函数来渲染矢量瓦片。相关帖子:https://stackoverflow.com/a/53317460/6399631
我的项目中包含Map
组件的文件;
import React, {Component} from "react";
import classNames from "classnames";
import {Map} from "react-leaflet";
class FdMap extends Component {
mapRef = (map) => {
if (map) {
this.mapLeaflet = map.leafletElement;
map.leafletElement.scrollWheelZoom.disable();
map.leafletElement.on("focus", function () {
map.leafletElement.scrollWheelZoom.enable();
});
map.leafletElement.on("blur", function () {
map.leafletElement.scrollWheelZoom.disable();
});
}
};
render() {
const {
className,
children
} = this.props;
const containerClassName = classNames(
"fd-map",
className
);
return (
<Map ref={this.mapRef}
{...this.props}
className={containerClassName}>
{children}
</Map>
);
};
}
export default FdMap;
我正在使用;
"react": "16.4.1",
"leaflet": "1.3.1"
你有什么解决方案吗?
发布于 2019-10-15 12:44:47
解决了这个问题。这个问题与react-leaflet
或props
无关。似乎我使用的是react-dom
版本的16.0.0
。将我的react-dom
版本更新到16.4.1
,现在我的问题就解决了。
https://stackoverflow.com/questions/58344553
复制相似问题