redux RTK查询-使用分页功能时,如何实现无限滚动和连接查询结果?

k4aesqcs  于 2022-12-23  发布在  其他
关注(0)|答案(2)|浏览(169)

我尝试在我的React Native应用程序中实现一个无限滚动。我的想法是使用一个平面列表,当我到达列表的末尾时,页面状态会递增,以便Redux RTK重新获取新数据。
然而,问题是当Redux RTK重新获取时,新的查询数据响应会覆盖现有的数据状态,我不知道是否有方法什至布尔值最终禁用此行为,因此它基本上会连接查询结果,因为否则我只会替换30张图像,但实际上我想显示额外的30张图像。
我很高兴听到可能的解决方案!

fnvucqvd

fnvucqvd1#

从RTK版本1.9开始,您现在可以使用merge选项进行此类操作。
要了解更多信息,您可以查看我对another question的回答。

cbjzeqam

cbjzeqam2#

我们的目标是取['一','二','三']
使用已提取的数据[“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

相关问题