Next.js Discord

Discord Forum

useInfiniteQuery not refetching on next navigation

Unanswered
Red-legged Kittiwake posted this in #help-forum
Open in Discord
Red-legged KittiwakeOP
the data stays the same on navigation until i refresh the page

25 Replies

Red-legged KittiwakeOP
maybe im not calling fetchNextPage() correctly?
if you can make a reproduction project or a demo that would be easier to help you
faster chance at getting help as the chance of people familiar with useInfiniteQuery is slim
Red-legged KittiwakeOP
does that mean i have to commit this to the repo
no
you can create a new repo and try to reproduce the bug/issue ure having
@Red-legged Kittiwake the data stays the same on navigation until i refresh the page
since this is too much irrelevant information
and not often people want to code for you so
Red-legged KittiwakeOP
well, normally useQuery should re-fetch the data on every next navigation?
is it wherever the QueryFn is called?
@Red-legged Kittiwake is it wherever the QueryFn is called?
no, its based on the defaults i gave you
if all of those condition are met then QueryFn will be called yes
Original message was deleted
umm 💀
what if you remove the initialData in your useInfiniteQuery? or add the refetchOnMount to true?
do the latter first
@aardani do the latter first
Red-legged KittiwakeOP
would it be better if i have a separate query (different query key and route) for the differnet pages?
that way when the user navigates back, the data that was previously fetched from infinite scroll doesn't have to be refetched
bc right now im using the same query for multiple pages but they have different filters so they have to be refetched every time
maybe i should've told you
i have different pages with different filters
right now they are calling the same query so they have to be refeteched every page change
should i make the pages have separate queries
@aardani what if you remove the initialData in your useInfiniteQuery? or add the `refetchOnMount` to true?
Red-legged KittiwakeOP
i tried and it didn't work
maybe it's not supposed to work like that because [see above]