问题描述
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 (将#修改为@)