滑动以刷新容器和FlatList时反应本机-无限循环

时间:2018-10-12 01:52:53

标签: node.js react-native native-base

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

...
...
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函数。如何解决?

1 个答案:

答案 0 :(得分:1)

您在定义this.onRefresh组件时正在呼叫<RefreshControl

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

相反,传递函数的引用

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

尝试上述更改,希望对您有所帮助!