android - 在用户到达平面列表末尾之前,首先调用 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
解决方案
FlatList
发生这种情况是因为您在加载数据之前渲染了。
您应该检查数据是否已加载,然后呈现列表。如果不是,它将触发该onEndReached
方法,因为初始列表呈现为空。
推荐阅读
- android - 如何获取对 ViewModel 的引用
- reactjs - 如何将以下 HOC 实现转换为 react 钩子实现
- vue.js - 如何从 vue 中的 ag-grid 获取显示行数据?
- c++ - 小字符串优化(调试与发布模式)
- c# - 在 Blazor 页面上检索自定义 Blazor 组件的所有实例
- c# - 如何控制 C# 中“抛出异常”窗口中显示的消息?
- r - 在所有行中更改值,但最高
- amazon-s3 - 使用 terraform .12.10+ 模板文件函数将 local_secrets 填充到 s3 存储桶
- macos - Mac OS Mojave 10.14.5 中的交叉编译
- python - 抓取和重定向