Skip to content

[useInfiniteQuery] Query data doesn't update even though queryFn has been called #6709

Answered by dr-zr
dr-zr asked this question in Q&A
Discussion options

You must be logged in to vote

I was able to solve the issue. It was because next page was fetching while the whole query was refeteched. Here's the whole breakdown

  1. Messages are rendered in a FlatList
  2. There was an onEndReached callback that calls messagesQuery.fetchNextPage
  3. I've added an optimization that displays up to 10 first messages while the screen is transitioning. After the transition has ended other messages are displayed.
  4. Since all 10 messages are rendered on the screen, the onEndReachedCb was called during transition, every time the screen was opened. This resulted in many redundant pages being fetched, even though the user didn't scroll nearly to the end
  5. When the messages query was invalidated, and the use…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@mkeyy0
Comment options

Answer selected by dr-zr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants