Prevent update cache with empty fetchPreviousPage response #4117
Unanswered
vitorcamachoo
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I've been struggling in the past few days trying to implement a simple bidirectional virtual list by using (
react-virtuoso
andinfinity query
). Explaining a bit what is the context, when reaching the end of the list, it will get the following pages and based on an interval, it will try to fetch the previous pages.So, when requesting the next pages we will be using an API field
ending_before
and when requesting the previous pages we will usestarting_after
which will be the date of the first event on the list.In addition to that, we are trying to display a new activity badge based on the new information that came from the previous page request.
The problem with this approach is when requesting previous pages based on the first event date, when the response is empty, it will be stored an empty array in the cache along with the parameters. What is the best way to prevent from this information being saved on the cache (pages and
pageParams
)? If the user will be on this page for a long time, it will have a lot of registries in the cache without any need.Regarding the new activity badge notification, I've tried to implement the logic in the onSuccess, by comparing the oldest first element with the newest first element.
So far I could use this way because
new
andold
have always the same information, so, what could be the best way to know if there are updates on the list based on the comparison of the first element?Beta Was this translation helpful? Give feedback.
All reactions