React Native - 滑动刷新容器和 FlatList 时的无限循环

React Native - Infinity Loop When Swipe to Refresh of Container and FlatList

我遇到了问题,请查看我的代码:

...
...
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}) =>
...
...

When i run the code above. It show alert multiple time (never end) of the onRefresh function. How to fix it ?

您在定义 <RefreshControl 组件时正在调用 this.onRefresh

<Content refreshControl={<RefreshControl ... onRefresh={this.onRefresh()} />} ... />

相反,传递函数的引用

<Content refreshControl={<RefreshControl ... onRefresh={this.onRefresh} />} ... />

尝试进行上述更改,希望这会有所帮助!