-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Description
Describe the bug
When using fetchMore(..., { previous: true }) to load a previous page and prepend it, if you then perform an action that causes ReactQuery to refetch, the requests are performed in the correct order but are appended instead of prepended. Currently there doesn't seem to be a way to let ReactQuery know how it should reconstruct the refetched data.
To Reproduce
Steps to reproduce the behavior:
- Go to this CodeSandbox which is a modified fork from the Infinite Loading example from the docs.
- Click on "Load more" a few times until no more messages can be loaded.
- Scroll down and click on "Go to another page".
- Click on "Back" to return to messages.
- See that the query is refetched, but now the messages are displayed in an incorrect order.
Expected behavior
If fetchMore(..., { previous: true }) is meant for infinite queries with a reversed direction, then useInfiniteQuery should accept some kind of option to indicate how background refetches should be handled.
Additional context
I may be misunderstanding the purpose of the previous feature. If that's the case then maybe additional details could be added to the docs to make it's purpose clearer. Nonetheless, I would definitely recommend adding an appendMode option where the direction of the list can be configured. This will allow ReactQuery's useInfiniteQuery to be used for reversed lists (such as chat messages, activity feeds, and the like).
PS: Issue #434 is related, and a possible solution seems to have been in development at some point, but I'm not sure if it ever got implemented or merged and the issue is now closed.
Thank you so much for the wonderful library! 🙂