将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,以便可以使用withLeaflet
函数在react-leaflet
内渲染矢量切片。相关文章: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"
你有什么解决办法吗?
答案 0 :(得分:0)
解决了此问题。该问题与react-leaflet
或props
无关。看来我正在使用react-dom
版本16.0.0
。将我的react-dom
版本更新为16.4.1
,现在我的问题已解决。