React native 使用Apollo+;获取新项目后,无限列表不会重新呈现;反应本机查询

React native 使用Apollo+;获取新项目后,无限列表不会重新呈现;反应本机查询,react-native,apollo,React Native,Apollo,当我到达列表的末尾时,fetchmore和updateQuery使用新的偏移量运行查询并获取新的项。但是列表本身使用旧数据和偏移量重新呈现 我在这里添加了代码以供审阅。总结一下,这里有一个最近交易的分区列表,基本上是一个按日期分组的常规平面列表。为了让无限滚动发挥作用,我按照文档使用偏移量进行分页。出于某种原因,每次我尝试获取更多时,偏移量并没有增加以匹配列表的大小,而是每隔一次更新一次。这怎么可能?Console.log语句似乎显示在返回新数据之前重新呈现的列表 从我第一次点击列表末尾开始记录

当我到达列表的末尾时,fetchmore和updateQuery使用新的偏移量运行查询并获取新的项。但是列表本身使用旧数据和偏移量重新呈现

我在这里添加了代码以供审阅。总结一下,这里有一个最近交易的分区列表,基本上是一个按日期分组的常规平面列表。为了让无限滚动发挥作用,我按照文档使用偏移量进行分页。出于某种原因,每次我尝试获取更多时,偏移量并没有增加以匹配列表的大小,而是每隔一次更新一次。这怎么可能?Console.log语句似乎显示在返回新数据之前重新呈现的列表

从我第一次点击列表末尾开始记录:

EndReached 1: offset is:  10
Top of query function
Top of query function
Query got transactions, returning txnList. txns.length:  10
TransactionList Render: transactions.length:  10
EndReached - UpdateQuery fn... offset:  10
EndReached - UpdateQuery fn... Prev length:  10
EndReached - UpdateQuery fn... Fetchmore length:  10
EndReached - UpdateQuery fn... New data length:  20 .  <---this gets returned and should cause a re-render but it doesn't
end1:偏移量为:10
顶部查询函数
顶部查询函数
查询已获取事务,返回txnList。txns.长度:10
TransactionList呈现:事务。长度:10
EndReach-UpdateQuery fn。。。抵销:10
EndReach-UpdateQuery fn。。。上一段长度:10
EndReach-UpdateQuery fn。。。获取更多长度:10
EndReach-UpdateQuery fn。。。新数据长度:20 修正:

如果查询不认为合并的对象(副本)与以前的查询结果有足够的不同,那么它似乎不会重新渲染-也许这是一个肤浅的比较?我通过在返回对象之前向对象添加测试消息发现了此修复

copy = prev;
copy.user.transactions = [...prev.user.transactions, ...fetchMoreResult.user.transactions]; // this change isn't detected. Shallow compare?
copy.message = "Hi there"; // this fixes the issue but is ugly
return copy;
更整洁的方法是使用lodash cloneDeep

copy = cloneDeep(prev);
copy.user.transactions = [...prev.user.transactions, ...fetchMoreResult.user.transactions];
return copy;
copy = prev;
copy.user.transactions = [...prev.user.transactions, ...fetchMoreResult.user.transactions]; // this change isn't detected. Shallow compare?
copy.message = "Hi there"; // this fixes the issue but is ugly
return copy;
copy = cloneDeep(prev);
copy.user.transactions = [...prev.user.transactions, ...fetchMoreResult.user.transactions];
return copy;