从自定义平面列表视图调用异步功能

时间:2019-09-19 17:57:20

标签: react-native asynchronous react-native-flatlist

我试图在客户平面视图中调用异步函数,但是在自定义平面视图中使用await导致出现错误:

async _customFlatlistView(item){
    promise = await SomeFunction(); 

    promise2 = await SomeOtherFunction();
}

2 个答案:

答案 0 :(得分:1)

await仅可用于async函数

_customFlatlistView = async item => {
  promise = await SomeFunction()
  promise2 = await SomeOtherFunction()
}

答案 1 :(得分:0)

await关键字只能用于将async关键字添加到方法签名中:

    async _customFlatlistView(item){
        promise = await SomeFunction(); 

        promise2 = await SomeOtherFunction();
    }
相关问题