You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For infinite scroll I'm currently using one of the @phryneas solution for infinite scroll that was answered in this long thread #1163 (comment)
This works almost for every case we have but looking at the new options available at v1.9.0 I'm revisiting this topic to see if I can get rid of some edge cases.
I'm still having some questions about how implement everything we have in the current solution with the new way. I'll use the documented example as a baseline, maybe it could be improved with the questions I have if found useful 🙂
listItems: build.query<string[], number>({
query: (pageNumber) => `/listItems?page=${pageNumber}`,
// Only have one cache entry because the arg always maps to one string
serializeQueryArgs: ({ endpointName }) => {
return endpointName
},
// Always merge incoming data to the cache entry
merge: (currentCache, newItems) => {
// Q&A1: If I reenter to the component, the page 0 would be refetched again at the end,
// is there a way to fix this? I think having access to queryArgs at merge would solve it
// Q&A2: How can it make it work with Invalidation tags and optimistic updates?
currentCache.push(...newItems)
},
// Refetch when the page arg changes
forceRefetch({ currentArg, previousArg }) {
// Q&A3: This forces a refetch whenever a queryArg has changed
// can I take into account the cached ttl to prevent forcing it every time I reenter the page?
return currentArg !== previousArg
},
}),
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
For infinite scroll I'm currently using one of the @phryneas solution for infinite scroll that was answered in this long thread #1163 (comment)
This works almost for every case we have but looking at the new options available at v1.9.0 I'm revisiting this topic to see if I can get rid of some edge cases.
I'm still having some questions about how implement everything we have in the current solution with the new way. I'll use the documented example as a baseline, maybe it could be improved with the questions I have if found useful 🙂
Beta Was this translation helpful? Give feedback.
All reactions