T
TanStack3y ago
rival-black

TWO PAGES WITH SAME DATA

I have two pages (analytics and research) But when i go to analytics and later go to research the data of analytics show in research
3 Replies
rival-black
rival-blackOP3y ago
ive two codes: const { data, fetchNextPage, refetch, isFetching, isFetchingNextPage, hasNextPage } = useInfiniteQuery( ['query'], async ({ pageParam = 0 }) => { const query = `/api/research?limit=${INFINITE_SCROLL_PAGINATION_RESULTS}&page=${pageParam}` const response = await fetch(query) const data = await response.json() return data as any[] }, { getNextPageParam: (_, pages) => { return pages.length + 1 }, initialData: { pages: [initialposts], pageParams: [1] } } ) const posts = data?.pages.flatMap((page) => page) ?? initialposts ////////////////// ` const { data, fetchNextPage, refetch, isFetching, isFetchingNextPage, hasNextPage } = useInfiniteQuery( ['query'], async ({ pageParam = 0 }) => { const query = /api/analytics?limit=${INFINITE_SCROLL_PAGINATIONRESULTS}&page=${pageParam}` const response = await fetch(query) const data = await response.json() return data as any[] }, { getNextPageParam: (, pages) => { return pages.length + 1 }, initialData: { pages: [initialposts], pageParams: [1] } } )```
rising-crimson
rising-crimson3y ago
The query keys need to be different of course. Otherwise they would be sharing a cache entry E.g ['research'] and ['analytics']
rising-crimson
rising-crimson3y ago
lol

Did you find this page helpful?