gpt4 book ai didi

reactjs - 警告 : Using UNSAFE_componentWillReceiveProps in strict mode

转载 作者:行者123 更新时间:2023-12-05 06:08:46 26 4
gpt4 key购买 nike

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

“警告:不建议在严格模式下使用 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)

最佳答案

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

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

关于reactjs - 警告 : Using UNSAFE_componentWillReceiveProps in strict mode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65026280/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com