【发布时间】:2020-07-26 09:24:46
【问题描述】:
我正在尝试使用Effect 在组件加载时设置地图的纬度和经度。问题是组件在 props 添加到 useEffect 之前加载和渲染。
useEffect(() => {
console.log(props.bandLocation)
// If I run this with a setTimeout it returns the data... but without the setTimeout it is an empty array. I need to set the latitude and longitude below to the data passed in through props...
setViewport({
latitude: props.bandLocation[0],
longitude: props.bandLocation[1],
width: '100%',
height: '200px',
zoom: 2,
})
}, [])
【问题讨论】:
标签: reactjs react-props use-effect