首页 > 解决方案 > 在用户到达平面列表末尾之前,首先调用 onEndReached 函数

问题描述

我想执行一个函数,当用户到达末尾flatList但该函数在每件事之前的组件加载时运行:

loadMore() {

alert('YouGot to end');

}


 render() {
    return (
    <FlatList

    data={this.state.foods}
    extraData={[this.state, this.props]}
    renderItem={this._renderItem}
    onEndReached={this.loadMore()}
    onEndReachedThreshold={0}
  />

  );
 }

加载更多警报会在组件首次启动时出现!甚至当我滚动到末尾时它也不再显示flatlist

标签: androidiosreact-native

解决方案


FlatList发生这种情况是因为您在加载数据之前渲染了。

您应该检查数据是否已加载,然后呈现列表。如果不是,它将触发该onEndReached方法,因为初始列表呈现为空。


推荐阅读