【发布时间】:2021-03-09 14:00:36
【问题描述】:
我尝试将谷歌地图添加到我的项目中,一切正常,但我的控制台中有以下警告,但不知道为什么以及如何修复它。
“警告:不建议在严格模式下使用 UNSAFE_componentWillReceiveProps,这可能表明您的代码中存在错误。有关详细信息,请参阅https://reactjs.org/link/unsafe-component-lifecycles。
- 将数据获取代码或副作用移至 componentDidUpdate。
- 如果您在 props 更改时更新状态,请重构您的代码以使用记忆技术或将其移至静态 getDerivedStateFromProps。了解更多信息:https://reactjs.org/link/derived-state
请更新以下组件:Wrapper"
下面是我的代码:
import React from 'react'
import { Map, GoogleApiWrapper, Marker } from 'google-maps-react';
const Location = (props) => {
const mapStyles = {
width: '60%',
height: '60%'
}
const {google} = props
return (
<div className="map-area">
<h1>Znajdź nas!</h1>
<Map
google={google}
zoom={13}
initialCenter={{
lat: 53.188,
lng: 18.066
}}
style={mapStyles}
>
<Marker />
</Map>
</div>);
}
export default GoogleApiWrapper({
apiKey: ('MY_TOKEN')
})(Location)
【问题讨论】:
标签: reactjs