【问题标题】:JSX element type 'GoogleMapReact' does not have any construct or call signatures.ts(2604)JSX 元素类型“GoogleMapReact”没有任何构造或调用 signatures.ts(2604)
【发布时间】:2020-01-12 13:01:40
【问题描述】:

我在下面的 TypeScript 代码中收到错误“JSX 元素类型 'GoogleMapReact' 没有任何构造或调用 signatures.ts(2604)”。我该如何解决这个问题?

import React, { useState } from "react";
import GoogleMapReact from "google-maps-react";

const AnyReactComponent = ({ text }: any) => <div>{text}</div>;

const SimpleMap = (props: any) => {
  const [center, setCenter] = useState({ lat: 11.0168, lng: 76.9558 });
  const [zoom, setZoom] = useState(11);
  return (
    <div style={{ height: "100vh", width: "100%" }}>
      <GoogleMapReact
        bootstrapURLKeys={{ key: "XXXXXXXXXXXXXXXXXXXX" }}
        defaultCenter={center}
        defaultZoom={zoom}
      >
        <AnyReactComponent lat={11.0168} lng={76.9558} text="My Marker" />
      </GoogleMapReact>
    </div>
  );
};

export default SimpleMap;

【问题讨论】:

    标签: javascript reactjs google-maps-react


    【解决方案1】:

    您正在导入 google-maps-react 库,但您正在使用该组件,就像您使用 google-map-react 一样(地图而不是地图)

    假设您要使用 google-map-react:删除 google-maps-react 依赖项,安装 google-map-react 并更改代码中的导入。

    【讨论】:

      猜你喜欢
      • 2022-11-13
      • 2019-04-26
      • 2021-11-30
      • 2016-10-07
      • 2016-03-05
      • 2021-09-21
      • 2021-12-26
      • 2017-12-05
      • 1970-01-01
      相关资源
      最近更新 更多