Reactjs 如何在信息窗口中显示结果[0]。格式化的\u地址

Reactjs 如何在信息窗口中显示结果[0]。格式化的\u地址,reactjs,google-maps,google-places,react-google-maps,Reactjs,Google Maps,Google Places,React Google Maps,我现在正在用react制作谷歌地图,我对placeId的显示结果有问题。我有以下代码: <Marker {...marker} key={i} position={marker.location} title={marker.title} icon={'icons/' + marker.type + '.png'} onClick={() => { props.toggleLocationsActive(i); }}

我现在正在用react制作谷歌地图,我对placeId的显示结果有问题。我有以下代码:

<Marker
    {...marker}
    key={i}
    position={marker.location}
    title={marker.title}
    icon={'icons/' + marker.type + '.png'}
    onClick={() => {
      props.toggleLocationsActive(i);
    }}
    //animation={DROP}
    >
    {i === props.activeKey && (
       geocodeByPlaceId(marker.place_id)
          .then(results => {
             const address = results[0].formatted_address;
             console.log(address);
          })
          .catch(error => console.error(error)),
       <InfoWindow onCloseClick={props.onToggleOpen}>
            <div>{ marker.title }</div>
       </InfoWindow>)}
   </Marker>
{
道具。切换位置激活(i);
}}
//动画={DROP}
>
{i==props.activeKey&&(
geocodeByPlaceId(标记位置)
。然后(结果=>{
常量地址=结果[0]。格式化的\u地址;
控制台日志(地址);
})
.catch(error=>console.error(error)),
{marker.title}
)}

我想在InfoWindow中显示从这个placeId获取的地址-显示{marker.title}。我不知道该怎么做。。。这里有一个链接指向GitHub存储库上的这个项目:也许你们中的一些人知道,如何解决这个问题。。。谢谢你的回答:)

我通过以下方式解决了这个问题:

document.getElementById('address').textContent = address;
我把这个代码放在“then”的一部分:

.then(results => {
     const address = results[0].formatted_address;
     console.log(address);
     document.getElementById('address').textContent = address;
})

我通过以下方式解决了这个问题:document.getElementById('address').textContent=address;