如何在模板文字中使用 Async Await

问题描述 投票:0回答:1

下面的代码仅返回字符串文字。我在某处读到模板字符串内的 Async-Await 需要具有顶级等待,但在我的情况下如何获得顶级等待?

<Autocomplete        
   renderOption={(props, option) => 
     <li {...props}> 
        {`${ async () => await getGeocode({placeId: option.place_id})
                                .then(results => getZipCode(results[0], true))()}
        `}
        </li> }
      />    
javascript async-await promise
1个回答
0
投票

我认为你应该从字符串文字中提取异步请求

可能会创建一个名为 Option 的新组件,它将 api 调用所需的参数作为 Props 并在 useEffect 中进行 api 调用

© www.soinside.com 2019 - 2024. All rights reserved.