[英]React-google-maps warnings
我最近開始學習React,我想用Google Maps API構建一個React App,所以我下載了React-google-maps包,但其文檔已過時。 我有此示例代碼。 控制台日志錯誤:
TL:DR如何修復此代碼
import React from "react"; import ReactDOM from "react-dom"; import { withGoogleMap, GoogleMap, Marker, InfoWindow, } from "react-google-maps"; const MapInit = withGoogleMap(props => ( <GoogleMap ref={props.onMapLoad} defaultZoom={1} defaultCenter={{ lat: -25.363882, lng: 131.044922 }} > </GoogleMap> )); class MapContainer extends React.Component { constructor(props) { super(props); this.state = { markers: [ {} ], }; this.handleMapLoad = this.handleMapLoad.bind(this); } handleMapLoad(map) { this._mapComponent = map; } render() { return ( <div style={{height: `100%`}}> <MapInit containerElement={ <div style={{ height: `100%` }} /> } mapElement={ <div style={{ height: `100%` }} /> } onMapLoad={this.handleMapLoad} /> </div> ); } } export default MapContainer;
它們是由庫生成的,該庫可能未更新為使用class
而不是createClass
並且正在從React導入PropTypes。
您可以通過瀏覽到node_modules並檢查源代碼來驗證這一點。 有點煩人,但是除了發送拉取請求自己修復之外,您無能為力。 :)
https://github.com/tomchentw/react-google-maps
版本號
您需要更新到react-google-maps v7.0.0才能擺脫棄用警告。
您可能要考慮改用
google-map-react ,它具有更多的社區活動,並且看起來質量更高。
對於第二次警告,請使用https://www.npmjs.com/package/prop-types 。
例如import PropTypes from 'prop-types';
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.