问题描述
我在现代中继中有这样的分页:
const CategoryContent = () => {
const { categoryQuery } = useRoute<CategoryContentScreenRouteProp>().params;
const { viewer } = useLazyLoadQuery<CategoryContentQuery>(
graphql`
query CategoryContentQuery(
$count: Int
$cursor: String
$category: String
) {
viewer {
...InfiniteCategories_viewer
@arguments(count: $count,cursor: $cursor,category: $category)
}
}
`,{ count: 7,category: categoryQuery }
);
//console.log("CategoryContent viewer",viewer);
return (
<Suspense fallback={<LoadingView />}>
<View>
<Text>CategoryContent</Text>
</View>
<InfiniteCategories viewer={viewer} />
</Suspense>
);
};
这是无限分页:
const InfiniteCategories = ({
viewer,}: {
viewer: InfiniteCategories_viewer$key;
}) => {
const { data,loadNext,hasNext,isLoadingNext } = usePaginationFragment<
InfiniteCategoriesPaginationQuery,any
>(
graphql`
fragment InfiniteCategories_viewer on Viewer
@argumentDefinitions(
count: { type: "Int",defaultValue: 7 }
cursor: { type: "String",defaultValue: null }
category: { type: "String" }
)
@refetchable(queryName: "InfiniteCategoriesPaginationQuery") {
merchants(first: $count,after: $cursor,category: $category)
@connection(key: "InfiniteCategories_viewer_merchants") {
pageInfo {
startCursor
endCursor
}
edges {
node {
id
category
logo
createdAt
isFavorite
pk
name
}
}
}
}
`,viewer
);
console.log("data InfiniteCategories",data);
return (
<StyledFlatList
{...{
data:
data && data.merchants && data.merchants.edges
? data.merchants.edges
: [],contentContainerStyle: styles.contentContainerStyle,showsVerticalScrollIndicator: false,keyExtractor: ({ cursor }) => cursor,renderItem: ({ item }) => (
<View>
<Text>{item.node.name}</Text>
</View>
),ListFooterComponent: () => {
if (isLoadingNext) return <ActivityIndicator />;
if (hasNext)
return (
<LoadMoreButton
onPress={() => {
loadNext(7);
}}
/>
);
return null;
},}}
/>
);
};
但是我的问题出在每个渲染中,例如当我回到屏幕时,它又被重新加载了吗?自分页以来,我该如何阻止它发生,用户将不得不再次加载更多以恢复其数据,而我不希望那样?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)