question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

useInfiniteQuery is fetching twice the first page

See original GitHub issue

Hi,

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:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:33 (5 by maintainers)

github_iconTop GitHub Comments

35reactions
alvesheliocommented, Jun 1, 2020

Thank you very much for the help, really appreciated guys. I’ve solved the problem by completely uninstalling react-query.

6reactions
TkDodocommented, Jan 20, 2021

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…

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found