我非常熟悉async await
但后端nodejs
。但是我遇到了一个场景,我必须在前端使用它。
我得到了对象数组,在这些对象中我得到lat lng
了这些地方。现在使用react-geocode
我可以获得单个的地名,lat lng
但我想在 map 函数中使用它来获取地名。所以正如我们所知,async
我必须async await
在那里使用。
这是代码
import Geocode from "react-geocode";
render = async() => {
const {
phase,
getCompanyUserRidesData
} = this.props
return (
<div>
<tbody>
await Promise.all(_.get(this.props, 'getCompanyUserRidesData', []).map(async(userRides,index) => {
const address = await Geocode.fromLatLng(22.685131,75.873468)
console.log(address.results[0].formatted_address)
return (
<tr key={index}>
<td>
{address.results[0].formatted_address}
</td>
<td>Goa</td>
<td>asdsad</td>
<td>{_.get(userRides,'driverId.email', '')}</td>
<td>{_.get(userRides,'driverId.mobile', '')}</td>
</tr>
)
}))
</tbody>
</div>
)
}
但是当我在这里使用 async 和 map 函数时,它不会返回任何内容。任何人都可以帮助我哪里出错了吗?