useInfiniteQuery is fetching twice the first page
See original GitHub issueHi,
I’ve been reading the doc and trying to figure out what I’m doing wrong but.
I have this code
const { status, data, error, isFetching, isFetchingMore, fetchMore, canFetchMore } = useInfiniteQuery(
"activities",
async (_key: any, nextPage = 1) => {
return eventsServices.getActivities({ ...selectedParams, page: nextPage, perPage: 30 });
},
{
getFetchMore: (lastGroup: IActivity[], groups: IActivity[][]) => {
return lastGroup?.length ? groups.length : false;
}
}
);
The firs time the page loads it will fetch my activities from page one, then when I scroll and fetchMore it’s called, it’s still fetching the first page.
According to the docs, there should be a nextCursor
property in lastGroup
but either the docs aren’t up to date or I’m doing something wrong because I’m getting an undefined
.
Also, according to the docs, By default, the info returned from getFetchMore will be supplied to the query function
. So I’m wondering if there’s something I’m doing wrong but it should be pretty straight forward according to the docs.
Any help would be greatly appreciated.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:33 (5 by maintainers)
Top Results From Across the Web
useInfiniteQuery is fetching twice the first page #520 - GitHub
I am having a similar issue. When fetching the initial first page of the infinite paginated request, it will fetch the page twice....
Read more >javascript - React useInfiniteQuery calls multiple times based ...
I have a created conversation list. When user click on the list, based on the id from the list, a chat messages view...
Read more >Infinite Queries | TanStack Query Docs
pageParams array containing the page params used to fetch the pages ... Waiting for useInfiniteQuery to request the first group of data by...
Read more >Why is my fetch getting called twice? : r/reactjs - Reddit
It shows it getting called twice in the console, but only shows once rendered on the page.
Read more >Infinite Scroll With React & React Query | Tutorial - YouTube
How to stop useEffect from running twice on mount or first render in ... Infinite Scroll in React with React Query useInfiniteQuery Hook ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thank you very much for the help, really appreciated guys. I’ve solved the problem by completely uninstalling react-query.
Now i would either add code to the working example until it looks like your code, or work from your code backwards until it looks like the example.
Could it be that the second request you are seeing is just because of
refetchOnWindowFocus
, because that happens a lot…