警告:在严格模式下使用 UNSAFE_componentWillReceiveProps

2024-03-11

我尝试将谷歌地图添加到我的项目中,一切正常,但我的控制台中出现以下警告,但不知道为什么以及如何修复它。

“警告:不建议在严格模式下使用 UNSAFE_componentWillReceiveProps,这可能表明代码中存在错误。请参阅https://reactjs.org/link/unsafe-component-lifecycles https://reactjs.org/link/unsafe-component-lifecycles了解详情。

  • 将数据获取代码或副作用移至 componentDidUpdate。
  • 如果您在 props 更改时更新状态,请重构您的代码以使用记忆技术或将其移至静态 getDerivedStateFromProps。了解更多信息:https://reactjs.org/link/衍生状态 https://reactjs.org/link/derived-state

请更新以下组件:包装器”

下面是我的代码:

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)

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

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

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

警告:在严格模式下使用 UNSAFE_componentWillReceiveProps 的相关文章

随机推荐