【问题标题】:RTK Query - How to implement inifinit scrolling and concatenate query results when using the pagination function?RTK查询-使用分页功能时如何实现无限滚动和拼接查询结果?
【发布时间】:2022-12-19 22:42:51
【问题描述】:
我正在尝试在我的 React Native 应用程序中实现一个 init 滚动。我的想法是使用 FlatList,当我到达列表末尾时,页面状态会递增,以便 Redux RTK 重新获取新数据。
但是,问题是当 Redux RTK 重新获取时,新的查询数据响应会覆盖现有数据状态,我不知道是否有办法甚至布尔值最终禁用此行为,所以它基本上会连接查询结果,因为否则我只会替换 30 张图像,但我实际上想显示另外 30 张图像。
我很高兴听到可能的解决方案!
【问题讨论】:
标签:
reactjs
react-native
redux
react-redux
rtk-query
【解决方案2】:
目标是采取类似 ['one', 'two', 'three']
运行获取并使用获取的数据 ['four', 'five', 'six']
update the state to be ['one', 'two', 'three','four', 'five', 'six']
one way would be setData([...data, ...newData]) I dont know how you are updating your local state
then also make sure to keep the pagination number so you fet the items from the last item that was fetched so if you fetched 5 items the next place to bring items in from would be from 6 - 10