如何解决阿波罗客户端 offsetLimitPagination 不起作用
export function useLazyProposalList() {
const [getQueueData,{ loading,data,error,fetchMore }] = useLazyQuery(PROPOSAL_LIST,{
fetchPolicy: 'no-cache',});
const proposalList = React.useMemo(() => {
if (!data) {
return null;
}
return transformProposals(data);
},[data]);
return {
getQueueData,fetchMore,loading,data: proposalList,};
}
在组件中
const {
getQueueData,data: queueData,fetchMore: fetchMoreProposals,// loadMore: loadMore,} = useLazyProposalList();
如果用户点击 fetch more
按钮,我会调用:fetchMoreProposals
。
await fetchMoreProposals({
variables: {
offset: visibleProposalList.length,},});
但这不会更新我的数据。我读到我们应该使用 offsetLimitPagination
,但我的查询数据不是数组本身。就像这样:queue { id: '1',items:[] }
并且因此,offsetLimitPagination
不起作用。所以我尝试合并
cache: new InMemoryCache({
typePolicies: {
Query: {
fields: {
queue: {
keyArgs: false,merge(existing,incoming) {
console.log(existing,incoming);
if (!incoming) return existing;
if (!existing) return incoming;
},}
但在控制台中,它只打印引用而不是真实数据。
可能是什么问题?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。