我遇到问题,请查看我的代码:
...
...
async onRefresh() {
this.setState({ loadingFlatList: true });
Alert.alert(
'Error',
"Refresheeeedd ....",
[
{text: 'OK', onPress: () => null },
],
{cancelable: false}
)
}
<Content refreshControl={<RefreshControl refreshing={this.state.loadingFlatList} onRefresh={this.onRefresh()} />} padder style={{backgroundColor: 'red'}} >
<Loader
loading={this.state.loading} />
<FlatList
data={this.state.listViewData}
// data={[{key: '1'}, {key: '2'}, {key: '3'}, {key: '4'}, {key: '5'}]}
// contentContainerStyle={customers.length === 0 && styles.centerEmptySet}
renderItem={({item}) =>
...
...
当我运行上面的代码时。它显示警报多个时间(从不结束) onRefresh函数。如何解决?
答案 0 :(得分:1)
您在定义this.onRefresh
组件时正在呼叫<RefreshControl
。
<Content refreshControl={<RefreshControl ... onRefresh={this.onRefresh()} />} ... />
相反,传递函数的引用
<Content refreshControl={<RefreshControl ... onRefresh={this.onRefresh} />} ... />
尝试上述更改,希望对您有所帮助!