【问题标题】:Warning: Using UNSAFE_componentWillReceiveProps in strict mode警告:在严格模式下使用 UNSAFE_componentWillReceiveProps
【发布时间】: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


    【解决方案1】:

    这是google-maps-react的当前版本和React的严格模式的问题。见:https://github.com/fullstackreact/google-maps-react/issues/476

    您可能不应该禁用严格模式,因此您必须自己修复库或等待有人这样做,然后升级。

    【讨论】:

      猜你喜欢
      • 2020-06-13
      • 1970-01-01
      • 2021-07-07
      • 1970-01-01
      • 1970-01-01
      • 2016-08-15
      • 2014-05-01
      • 2021-09-25
      相关资源
      最近更新 更多